Skip to content

Commit

Permalink
Complete unregisterProtocolHandler() implementation.
Browse files Browse the repository at this point in the history
BUG=392016

Review URL: https://codereview.chromium.org/368243009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282960 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
sanjoy.pal@samsung.com committed Jul 14, 2014
1 parent f1b252f commit f5273e5
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ class RegisterProtocolHandlerBrowserTest : public InProcessBrowserTest {
registry->is_loading_ = false;
ASSERT_TRUE(registry->IsHandledProtocol(protocol));
}
void RemoveProtocolHandler(const std::string& protocol,
const GURL& url) {
ProtocolHandler handler = ProtocolHandler::CreateProtocolHandler(protocol,
url);
ProtocolHandlerRegistry* registry =
ProtocolHandlerRegistryFactory::GetForProfile(browser()->profile());
registry->RemoveHandler(handler);
ASSERT_FALSE(registry->IsHandledProtocol(protocol));
}
};

IN_PROC_BROWSER_TEST_F(RegisterProtocolHandlerBrowserTest,
Expand All @@ -77,6 +86,27 @@ IN_PROC_BROWSER_TEST_F(RegisterProtocolHandlerBrowserTest,
ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKWITH));
}

IN_PROC_BROWSER_TEST_F(RegisterProtocolHandlerBrowserTest,
UnregisterProtocolHandler) {
scoped_ptr<TestRenderViewContextMenu> menu(
CreateContextMenu(GURL("http://www.google.com/")));
ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKWITH));

AddProtocolHandler(std::string("web+search"),
GURL("http://www.google.com/%s"));
GURL url("web+search:testing");
ProtocolHandlerRegistry* registry =
ProtocolHandlerRegistryFactory::GetForProfile(browser()->profile());
ASSERT_EQ(1u, registry->GetHandlersFor(url.scheme()).size());
menu.reset(CreateContextMenu(url));
ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKWITH));
RemoveProtocolHandler(std::string("web+search"),
GURL("http://www.google.com/%s"));
ASSERT_EQ(0u, registry->GetHandlersFor(url.scheme()).size());
menu.reset(CreateContextMenu(url));
ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKWITH));
}

IN_PROC_BROWSER_TEST_F(RegisterProtocolHandlerBrowserTest, CustomHandler) {
ASSERT_TRUE(test_server()->Start());
GURL handler_url = test_server()->GetURL("files/custom_handler_foo.html");
Expand Down
19 changes: 19 additions & 0 deletions chrome/browser/ui/browser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,25 @@ void Browser::RegisterProtocolHandler(WebContents* web_contents,
}
}

void Browser::UnregisterProtocolHandler(WebContents* web_contents,
const std::string& protocol,
const GURL& url,
bool user_gesture) {
// user_gesture will be used in case we decide to have confirmation bubble
// for user while un-registering the handler.
Profile* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
if (profile->IsOffTheRecord())
return;

ProtocolHandler handler =
ProtocolHandler::CreateProtocolHandler(protocol, url);

ProtocolHandlerRegistry* registry =
ProtocolHandlerRegistryFactory::GetForProfile(profile);
registry->RemoveHandler(handler);
}

void Browser::UpdatePreferredSize(WebContents* source,
const gfx::Size& pref_size) {
window_->UpdatePreferredSize(source, pref_size);
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/ui/browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,10 @@ class Browser : public TabStripModelObserver,
const std::string& protocol,
const GURL& url,
bool user_gesture) OVERRIDE;
virtual void UnregisterProtocolHandler(content::WebContents* web_contents,
const std::string& protocol,
const GURL& url,
bool user_gesture) OVERRIDE;
virtual void UpdatePreferredSize(content::WebContents* source,
const gfx::Size& pref_size) OVERRIDE;
virtual void ResizeDueToAutoResize(content::WebContents* source,
Expand Down
16 changes: 16 additions & 0 deletions content/browser/web_contents/web_contents_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@ bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
OnRegisterProtocolHandler)
IPC_MESSAGE_HANDLER(ViewHostMsg_UnregisterProtocolHandler,
OnUnregisterProtocolHandler)
IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
Expand Down Expand Up @@ -2726,6 +2728,20 @@ void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
}

void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
const GURL& url,
bool user_gesture) {
if (!delegate_)
return;

ChildProcessSecurityPolicyImpl* policy =
ChildProcessSecurityPolicyImpl::GetInstance();
if (policy->IsPseudoScheme(protocol))
return;

delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
}

void WebContentsImpl::OnFindReply(int request_id,
int number_of_matches,
const gfx::Rect& selection_rect,
Expand Down
3 changes: 3 additions & 0 deletions content/browser/web_contents/web_contents_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,9 @@ class CONTENT_EXPORT WebContentsImpl
const GURL& url,
const base::string16& title,
bool user_gesture);
void OnUnregisterProtocolHandler(const std::string& protocol,
const GURL& url,
bool user_gesture);
void OnFindReply(int request_id,
int number_of_matches,
const gfx::Rect& selection_rect,
Expand Down
6 changes: 6 additions & 0 deletions content/common/view_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,12 @@ IPC_MESSAGE_ROUTED4(ViewHostMsg_RegisterProtocolHandler,
base::string16 /* title */,
bool /* user_gesture */)

// Unregister the registered handler for URL requests with the given scheme.
IPC_MESSAGE_ROUTED3(ViewHostMsg_UnregisterProtocolHandler,
std::string /* scheme */,
GURL /* url */,
bool /* user_gesture */)

// Stores new inspector setting in the profile.
// TODO(jam): this should be in the chrome module
IPC_MESSAGE_ROUTED2(ViewHostMsg_UpdateInspectorSetting,
Expand Down
8 changes: 8 additions & 0 deletions content/public/browser/web_contents_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,14 @@ class CONTENT_EXPORT WebContentsDelegate {
const GURL& url,
bool user_gesture) {}

// Unregister the registered handler for URL requests with the given scheme.
// |user_gesture| is true if the registration is made in the context of a user
// gesture.
virtual void UnregisterProtocolHandler(WebContents* web_contents,
const std::string& protocol,
const GURL& url,
bool user_gesture) {}

// Result of string search in the page. This includes the number of matches
// found and the selection rect (in screen coordinates) for the string found.
// If |final_update| is false, it indicates that more results follow.
Expand Down
14 changes: 14 additions & 0 deletions content/renderer/render_view_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3975,6 +3975,20 @@ void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
user_gesture));
}

void RenderViewImpl::unregisterProtocolHandler(const WebString& scheme,
const WebURL& base_url,
const WebURL& url) {
bool user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
GURL base(base_url);
GURL absolute_url = base.Resolve(base::UTF16ToUTF8(url.string()));
if (base.GetOrigin() != absolute_url.GetOrigin())
return;
Send(new ViewHostMsg_UnregisterProtocolHandler(routing_id_,
base::UTF16ToUTF8(scheme),
absolute_url,
user_gesture));
}

blink::WebPageVisibilityState RenderViewImpl::visibilityState() const {
blink::WebPageVisibilityState current_state = is_hidden() ?
blink::WebPageVisibilityStateHidden :
Expand Down
3 changes: 3 additions & 0 deletions content/renderer/render_view_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,9 @@ class CONTENT_EXPORT RenderViewImpl
const blink::WebURL& base_url,
const blink::WebURL& url,
const blink::WebString& title);
virtual void unregisterProtocolHandler(const blink::WebString& scheme,
const blink::WebURL& base_url,
const blink::WebURL& url);
virtual blink::WebPageVisibilityState visibilityState() const;
virtual blink::WebPushClient* webPushClient();
virtual void draggableRegionsChanged();
Expand Down

0 comments on commit f5273e5

Please sign in to comment.