Chromium Code Reviews| Index: chrome/browser/guest_view/web_view/web_view_guest.cc |
| diff --git a/chrome/browser/guest_view/web_view/web_view_guest.cc b/chrome/browser/guest_view/web_view/web_view_guest.cc |
| index c9e75d13a0b4b9f35f3275b71f49330c000bfe3b..839a1b9b9a7e515e49eee761f63dcd039645dd65 100644 |
| --- a/chrome/browser/guest_view/web_view/web_view_guest.cc |
| +++ b/chrome/browser/guest_view/web_view/web_view_guest.cc |
| @@ -8,18 +8,16 @@ |
| #include "base/strings/stringprintf.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "chrome/browser/chrome_notification_types.h" |
| -#include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
| #include "chrome/browser/extensions/api/web_view/web_view_internal_api.h" |
| #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
| #include "chrome/browser/extensions/menu_manager.h" |
| #include "chrome/browser/extensions/script_executor.h" |
| #include "chrome/browser/favicon/favicon_tab_helper.h" |
| -#include "chrome/browser/geolocation/geolocation_permission_context.h" |
| -#include "chrome/browser/geolocation/geolocation_permission_context_factory.h" |
| #include "chrome/browser/guest_view/guest_view_constants.h" |
| #include "chrome/browser/guest_view/guest_view_manager.h" |
| #include "chrome/browser/guest_view/web_view/web_view_constants.h" |
| +#include "chrome/browser/guest_view/web_view/web_view_permission_helper.h" |
| #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" |
| #include "chrome/browser/guest_view/web_view/web_view_renderer_state.h" |
| #include "chrome/browser/renderer_context_menu/context_menu_delegate.h" |
| @@ -65,10 +63,6 @@ |
| #endif // defined(ENABLE_FULL_PRINTING) |
| #endif // defined(ENABLE_PRINTING) |
| -#if defined(ENABLE_PLUGINS) |
| -#include "chrome/browser/guest_view/web_view/plugin_permission_helper.h" |
| -#endif |
| - |
| #if defined(OS_CHROMEOS) |
| #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| #endif |
| @@ -120,30 +114,6 @@ static std::string TerminationStatusToString(base::TerminationStatus status) { |
| return "unknown"; |
| } |
| -static std::string PermissionTypeToString(WebViewPermissionType type) { |
| - switch (type) { |
| - case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: |
| - return webview::kPermissionTypeDownload; |
| - case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: |
| - return webview::kPermissionTypeFileSystem; |
| - case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: |
| - return webview::kPermissionTypeGeolocation; |
| - case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: |
| - return webview::kPermissionTypeDialog; |
| - case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: |
| - return webview::kPermissionTypeLoadPlugin; |
| - case WEB_VIEW_PERMISSION_TYPE_MEDIA: |
| - return webview::kPermissionTypeMedia; |
| - case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: |
| - return webview::kPermissionTypeNewWindow; |
| - case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: |
| - return webview::kPermissionTypePointerLock; |
| - default: |
| - NOTREACHED(); |
| - return std::string(); |
| - } |
| -} |
| - |
| std::string GetStoragePartitionIdFromSiteURL(const GURL& site_url) { |
| const std::string& partition_id = site_url.query(); |
| bool persist_storage = site_url.path().find("persist") != std::string::npos; |
| @@ -167,9 +137,6 @@ void AttachWebViewHelpers(WebContents* contents) { |
| FaviconTabHelper::CreateForWebContents(contents); |
| extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( |
| contents); |
| -#if defined(ENABLE_PLUGINS) |
| - PluginPermissionHelper::CreateForWebContents(contents); |
| -#endif |
| #if defined(ENABLE_PRINTING) |
| #if defined(ENABLE_FULL_PRINTING) |
| printing::PrintViewManager::CreateForWebContents(contents); |
| @@ -216,7 +183,6 @@ WebViewGuest::WebViewGuest(content::BrowserContext* browser_context, |
| int guest_instance_id) |
| : GuestView<WebViewGuest>(browser_context, guest_instance_id), |
| pending_context_menu_request_id_(0), |
| - next_permission_request_id_(0), |
| is_overriding_user_agent_(false), |
| main_frame_id_(0), |
| chromevox_injected_(false), |
| @@ -260,89 +226,6 @@ int WebViewGuest::GetViewInstanceId(WebContents* contents) { |
| } |
| // static |
| -void WebViewGuest::RecordUserInitiatedUMA(const PermissionResponseInfo& info, |
| - bool allow) { |
| - if (allow) { |
| - // Note that |allow| == true means the embedder explicitly allowed the |
| - // request. For some requests they might still fail. An example of such |
| - // scenario would be: an embedder allows geolocation request but doesn't |
| - // have geolocation access on its own. |
| - switch (info.permission_type) { |
| - case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: |
| - content::RecordAction( |
| - UserMetricsAction("WebView.PermissionAllow.Download")); |
| - break; |
| - case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: |
| - content::RecordAction( |
| - UserMetricsAction("WebView.PermissionAllow.FileSystem")); |
| - break; |
| - case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: |
| - content::RecordAction( |
| - UserMetricsAction("WebView.PermissionAllow.Geolocation")); |
| - break; |
| - case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: |
| - content::RecordAction( |
| - UserMetricsAction("WebView.PermissionAllow.JSDialog")); |
| - break; |
| - case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: |
| - content::RecordAction( |
| - UserMetricsAction("WebView.Guest.PermissionAllow.PluginLoad")); |
| - case WEB_VIEW_PERMISSION_TYPE_MEDIA: |
| - content::RecordAction( |
| - UserMetricsAction("WebView.PermissionAllow.Media")); |
| - break; |
| - case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: |
| - content::RecordAction( |
| - UserMetricsAction("BrowserPlugin.PermissionAllow.NewWindow")); |
| - break; |
| - case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: |
| - content::RecordAction( |
| - UserMetricsAction("WebView.PermissionAllow.PointerLock")); |
| - break; |
| - default: |
| - break; |
| - } |
| - } else { |
| - switch (info.permission_type) { |
| - case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: |
| - content::RecordAction( |
| - UserMetricsAction("WebView.PermissionDeny.Download")); |
| - break; |
| - case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: |
| - content::RecordAction( |
| - UserMetricsAction("WebView.PermissionDeny.FileSystem")); |
| - break; |
| - case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: |
| - content::RecordAction( |
| - UserMetricsAction("WebView.PermissionDeny.Geolocation")); |
| - break; |
| - case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: |
| - content::RecordAction( |
| - UserMetricsAction("WebView.PermissionDeny.JSDialog")); |
| - break; |
| - case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: |
| - content::RecordAction( |
| - UserMetricsAction("WebView.Guest.PermissionDeny.PluginLoad")); |
| - break; |
| - case WEB_VIEW_PERMISSION_TYPE_MEDIA: |
| - content::RecordAction( |
| - UserMetricsAction("WebView.PermissionDeny.Media")); |
| - break; |
| - case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: |
| - content::RecordAction( |
| - UserMetricsAction("BrowserPlugin.PermissionDeny.NewWindow")); |
| - break; |
| - case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: |
| - content::RecordAction( |
| - UserMetricsAction("WebView.PermissionDeny.PointerLock")); |
| - break; |
| - default: |
| - break; |
| - } |
| - } |
| -} |
| - |
| -// static |
| scoped_ptr<base::ListValue> WebViewGuest::MenuModelToValue( |
| const ui::SimpleMenuModel& menu_model) { |
| scoped_ptr<base::ListValue> items(new base::ListValue()); |
| @@ -481,12 +364,14 @@ void WebViewGuest::DidInitialize() { |
| #endif |
| AttachWebViewHelpers(guest_web_contents()); |
|
Fady Samuel
2014/07/07 15:01:52
Make AttachWebViewHelpers a non-static method and
Xi Han
2014/07/08 15:59:13
Done.
|
| + web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); |
| } |
| void WebViewGuest::DidStopLoading() { |
| scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| - DispatchEvent(new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); |
| + DispatchEventToEmbedder( |
| + new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); |
| } |
| void WebViewGuest::EmbedderDestroyed() { |
| @@ -538,14 +423,15 @@ bool WebViewGuest::AddMessageToConsole(WebContents* source, |
| args->SetString(webview::kMessage, message); |
| args->SetInteger(webview::kLine, line_no); |
| args->SetString(webview::kSourceId, source_id); |
| - DispatchEvent( |
| + DispatchEventToEmbedder( |
| new GuestViewBase::Event(webview::kEventConsoleMessage, args.Pass())); |
| return true; |
| } |
| void WebViewGuest::CloseContents(WebContents* source) { |
| scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| - DispatchEvent(new GuestViewBase::Event(webview::kEventClose, args.Pass())); |
| + DispatchEventToEmbedder( |
| + new GuestViewBase::Event(webview::kEventClose, args.Pass())); |
| } |
| void WebViewGuest::FindReply(WebContents* source, |
| @@ -573,8 +459,8 @@ bool WebViewGuest::HandleContextMenu( |
| MenuModelToValue(pending_menu_->menu_model()); |
| args->Set(webview::kContextMenuItems, items.release()); |
| args->SetInteger(webview::kRequestId, request_id); |
| - DispatchEvent(new GuestViewBase::Event(webview::kEventContextMenu, |
| - args.Pass())); |
| + DispatchEventToEmbedder( |
| + new GuestViewBase::Event(webview::kEventContextMenu, args.Pass())); |
| return true; |
| } |
| @@ -602,7 +488,7 @@ void WebViewGuest::LoadProgressChanged(content::WebContents* source, |
| scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| args->SetString(guestview::kUrl, guest_web_contents()->GetURL().spec()); |
| args->SetDouble(webview::kProgress, progress); |
| - DispatchEvent( |
| + DispatchEventToEmbedder( |
| new GuestViewBase::Event(webview::kEventLoadProgress, args.Pass())); |
| } |
| @@ -613,7 +499,7 @@ void WebViewGuest::LoadAbort(bool is_top_level, |
| args->SetBoolean(guestview::kIsTopLevel, is_top_level); |
| args->SetString(guestview::kUrl, url.possibly_invalid_spec()); |
| args->SetString(guestview::kReason, error_type); |
| - DispatchEvent( |
| + DispatchEventToEmbedder( |
| new GuestViewBase::Event(webview::kEventLoadAbort, args.Pass())); |
| } |
| @@ -672,7 +558,7 @@ void WebViewGuest::RendererResponsive(content::WebContents* source) { |
| scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| args->SetInteger(webview::kProcessId, |
| guest_web_contents()->GetRenderProcessHost()->GetID()); |
| - DispatchEvent( |
| + DispatchEventToEmbedder( |
| new GuestViewBase::Event(webview::kEventResponsive, args.Pass())); |
| } |
| @@ -680,7 +566,7 @@ void WebViewGuest::RendererUnresponsive(content::WebContents* source) { |
| scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| args->SetInteger(webview::kProcessId, |
| guest_web_contents()->GetRenderProcessHost()->GetID()); |
| - DispatchEvent( |
| + DispatchEventToEmbedder( |
| new GuestViewBase::Event(webview::kEventUnresponsive, args.Pass())); |
| } |
| @@ -740,154 +626,6 @@ void WebViewGuest::Reload() { |
| guest_web_contents()->GetController().Reload(false); |
| } |
| -void WebViewGuest::RequestFileSystemPermission( |
| - const GURL& url, |
| - bool allowed_by_default, |
| - const base::Callback<void(bool)>& callback) { |
| - base::DictionaryValue request_info; |
| - request_info.Set(guestview::kUrl, base::Value::CreateStringValue(url.spec())); |
| - RequestPermission( |
| - WEB_VIEW_PERMISSION_TYPE_FILESYSTEM, |
| - request_info, |
| - base::Bind(&WebViewGuest::OnWebViewFileSystemPermissionResponse, |
| - base::Unretained(this), |
| - callback), |
| - allowed_by_default); |
| -} |
| - |
| -void WebViewGuest::OnWebViewFileSystemPermissionResponse( |
| - const base::Callback<void(bool)>& callback, |
| - bool allow, |
| - const std::string& user_input) { |
| - callback.Run(allow && attached()); |
| -} |
| - |
| -void WebViewGuest::RequestGeolocationPermission( |
| - int bridge_id, |
| - const GURL& requesting_frame, |
| - bool user_gesture, |
| - const base::Callback<void(bool)>& callback) { |
| - base::DictionaryValue request_info; |
| - request_info.Set(guestview::kUrl, |
| - base::Value::CreateStringValue(requesting_frame.spec())); |
| - request_info.Set(guestview::kUserGesture, |
| - base::Value::CreateBooleanValue(user_gesture)); |
| - |
| - // It is safe to hold an unretained pointer to WebViewGuest because this |
| - // callback is called from WebViewGuest::SetPermission. |
| - const PermissionResponseCallback permission_callback = |
| - base::Bind(&WebViewGuest::OnWebViewGeolocationPermissionResponse, |
| - base::Unretained(this), |
| - bridge_id, |
| - user_gesture, |
| - callback); |
| - int request_id = RequestPermission( |
| - WEB_VIEW_PERMISSION_TYPE_GEOLOCATION, |
| - request_info, |
| - permission_callback, |
| - false /* allowed_by_default */); |
| - bridge_id_to_request_id_map_[bridge_id] = request_id; |
| -} |
| - |
| -void WebViewGuest::OnWebViewGeolocationPermissionResponse( |
| - int bridge_id, |
| - bool user_gesture, |
| - const base::Callback<void(bool)>& callback, |
| - bool allow, |
| - const std::string& user_input) { |
| - // The <webview> embedder has allowed the permission. We now need to make sure |
| - // that the embedder has geolocation permission. |
| - RemoveBridgeID(bridge_id); |
| - |
| - if (!allow || !attached()) { |
| - callback.Run(false); |
| - return; |
| - } |
| - |
| - Profile* profile = Profile::FromBrowserContext(browser_context()); |
| - GeolocationPermissionContextFactory::GetForProfile(profile)-> |
| - RequestGeolocationPermission( |
| - embedder_web_contents(), |
| - // The geolocation permission request here is not initiated |
| - // through WebGeolocationPermissionRequest. We are only interested |
| - // in the fact whether the embedder/app has geolocation |
| - // permission. Therefore we use an invalid |bridge_id|. |
| - -1, |
| - embedder_web_contents()->GetLastCommittedURL(), |
| - user_gesture, |
| - callback, |
| - NULL); |
| -} |
| - |
| -void WebViewGuest::CancelGeolocationPermissionRequest(int bridge_id) { |
| - int request_id = RemoveBridgeID(bridge_id); |
| - RequestMap::iterator request_itr = |
| - pending_permission_requests_.find(request_id); |
| - |
| - if (request_itr == pending_permission_requests_.end()) |
| - return; |
| - |
| - pending_permission_requests_.erase(request_itr); |
| -} |
| - |
| -void WebViewGuest::OnWebViewMediaPermissionResponse( |
| - const content::MediaStreamRequest& request, |
| - const content::MediaResponseCallback& callback, |
| - bool allow, |
| - const std::string& user_input) { |
| - if (!allow || !attached()) { |
| - // Deny the request. |
| - callback.Run(content::MediaStreamDevices(), |
| - content::MEDIA_DEVICE_INVALID_STATE, |
| - scoped_ptr<content::MediaStreamUI>()); |
| - return; |
| - } |
| - if (!embedder_web_contents()->GetDelegate()) |
| - return; |
| - |
| - embedder_web_contents()->GetDelegate()-> |
| - RequestMediaAccessPermission(embedder_web_contents(), request, callback); |
| -} |
| - |
| -void WebViewGuest::OnWebViewDownloadPermissionResponse( |
| - const base::Callback<void(bool)>& callback, |
| - bool allow, |
| - const std::string& user_input) { |
| - callback.Run(allow && attached()); |
| -} |
| - |
| -void WebViewGuest::OnWebViewPointerLockPermissionResponse( |
| - const base::Callback<void(bool)>& callback, |
| - bool allow, |
| - const std::string& user_input) { |
| - callback.Run(allow && attached()); |
| -} |
| - |
| -WebViewGuest::SetPermissionResult WebViewGuest::SetPermission( |
| - int request_id, |
| - PermissionResponseAction action, |
| - const std::string& user_input) { |
| - RequestMap::iterator request_itr = |
| - pending_permission_requests_.find(request_id); |
| - |
| - if (request_itr == pending_permission_requests_.end()) |
| - return SET_PERMISSION_INVALID; |
| - |
| - const PermissionResponseInfo& info = request_itr->second; |
| - bool allow = (action == ALLOW) || |
| - ((action == DEFAULT) && info.allowed_by_default); |
| - |
| - info.callback.Run(allow, user_input); |
| - |
| - // Only record user initiated (i.e. non-default) actions. |
| - if (action != DEFAULT) |
| - RecordUserInitiatedUMA(info, allow); |
| - |
| - pending_permission_requests_.erase(request_itr); |
| - |
| - return allow ? SET_PERMISSION_ALLOWED : SET_PERMISSION_DENIED; |
| -} |
| - |
| void WebViewGuest::SetUserAgentOverride( |
| const std::string& user_agent_override) { |
| if (!attached()) |
| @@ -940,34 +678,13 @@ void WebViewGuest::FileSystemAccessedAsync(int render_process_id, |
| int request_id, |
| const GURL& url, |
| bool blocked_by_policy) { |
| - WebViewGuest* guest = |
| - WebViewGuest::FromFrameID(render_process_id, render_frame_id); |
| - DCHECK(guest); |
| - guest->RequestFileSystemPermission( |
| - url, |
| - !blocked_by_policy, |
| - base::Bind(&WebViewGuest::FileSystemAccessedAsyncResponse, |
| - render_process_id, |
| - render_frame_id, |
| - request_id, |
| - url)); |
| -} |
| - |
| -// static |
| -void WebViewGuest::FileSystemAccessedAsyncResponse(int render_process_id, |
| - int render_frame_id, |
| - int request_id, |
| - const GURL& url, |
| - bool allowed) { |
| - TabSpecificContentSettings::FileSystemAccessed( |
| - render_process_id, render_frame_id, url, !allowed); |
| - content::RenderFrameHost* render_frame_host = |
| - content::RenderFrameHost::FromID(render_process_id, render_frame_id); |
| - if (!render_frame_host) |
| - return; |
| - render_frame_host->Send( |
| - new ChromeViewMsg_RequestFileSystemAccessAsyncResponse( |
| - render_frame_id, request_id, allowed)); |
| + WebViewPermissionHelper* web_view_permission_helper = |
| + WebViewPermissionHelper::FromFrameID(render_process_id, render_frame_id); |
| + web_view_permission_helper->FileSystemAccessedAsync(render_process_id, |
| + render_frame_id, |
| + request_id, |
| + url, |
| + blocked_by_policy); |
| } |
| // static |
| @@ -976,34 +693,13 @@ void WebViewGuest::FileSystemAccessedSync(int render_process_id, |
| const GURL& url, |
| bool blocked_by_policy, |
| IPC::Message* reply_msg) { |
| - WebViewGuest* guest = |
| - WebViewGuest::FromFrameID(render_process_id, render_frame_id); |
| - DCHECK(guest); |
| - guest->RequestFileSystemPermission( |
| - url, |
| - !blocked_by_policy, |
| - base::Bind(&WebViewGuest::FileSystemAccessedSyncResponse, |
| - render_process_id, |
| - render_frame_id, |
| - url, |
| - reply_msg)); |
| -} |
| - |
| -// static |
| -void WebViewGuest::FileSystemAccessedSyncResponse(int render_process_id, |
| - int render_frame_id, |
| - const GURL& url, |
| - IPC::Message* reply_msg, |
| - bool allowed) { |
| - TabSpecificContentSettings::FileSystemAccessed( |
| - render_process_id, render_frame_id, url, !allowed); |
| - ChromeViewHostMsg_RequestFileSystemAccessSync::WriteReplyParams(reply_msg, |
| - allowed); |
| - content::RenderFrameHost* render_frame_host = |
| - content::RenderFrameHost::FromID(render_process_id, render_frame_id); |
| - if (!render_frame_id) |
| - return; |
| - render_frame_host->Send(reply_msg); |
| + WebViewPermissionHelper* web_view_permission_helper = |
| + WebViewPermissionHelper::FromFrameID(render_process_id, render_frame_id); |
| + web_view_permission_helper->FileSystemAccessedSync(render_process_id, |
| + render_frame_id, |
| + url, |
| + blocked_by_policy, |
| + reply_msg); |
| } |
| WebViewGuest::~WebViewGuest() { |
| @@ -1024,7 +720,7 @@ void WebViewGuest::DidCommitProvisionalLoadForFrame( |
| guest_web_contents()->GetController().GetEntryCount()); |
| args->SetInteger(webview::kInternalProcessId, |
| guest_web_contents()->GetRenderProcessHost()->GetID()); |
| - DispatchEvent( |
| + DispatchEventToEmbedder( |
| new GuestViewBase::Event(webview::kEventLoadCommit, args.Pass())); |
| // Update the current zoom factor for the new page. |
| @@ -1057,7 +753,7 @@ void WebViewGuest::DidStartProvisionalLoadForFrame( |
| scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| args->SetString(guestview::kUrl, validated_url.spec()); |
| args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); |
| - DispatchEvent( |
| + DispatchEventToEmbedder( |
| new GuestViewBase::Event(webview::kEventLoadStart, args.Pass())); |
| } |
| @@ -1086,7 +782,8 @@ void WebViewGuest::RenderProcessGone(base::TerminationStatus status) { |
| args->SetInteger(webview::kProcessId, |
| guest_web_contents()->GetRenderProcessHost()->GetID()); |
| args->SetString(webview::kReason, TerminationStatusToString(status)); |
| - DispatchEvent(new GuestViewBase::Event(webview::kEventExit, args.Pass())); |
| + DispatchEventToEmbedder( |
| + new GuestViewBase::Event(webview::kEventExit, args.Pass())); |
| } |
| void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { |
| @@ -1111,13 +808,13 @@ void WebViewGuest::ReportFrameNameChange(const std::string& name) { |
| name_ = name; |
| scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| args->SetString(webview::kName, name); |
| - DispatchEvent( |
| + DispatchEventToEmbedder( |
| new GuestViewBase::Event(webview::kEventFrameNameChanged, args.Pass())); |
| } |
| void WebViewGuest::LoadHandlerCalled() { |
| scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| - DispatchEvent( |
| + DispatchEventToEmbedder( |
| new GuestViewBase::Event(webview::kEventContentLoad, args.Pass())); |
| } |
| @@ -1128,7 +825,7 @@ void WebViewGuest::LoadRedirect(const GURL& old_url, |
| args->SetBoolean(guestview::kIsTopLevel, is_top_level); |
| args->SetString(webview::kNewURL, new_url.spec()); |
| args->SetString(webview::kOldURL, old_url.spec()); |
| - DispatchEvent( |
| + DispatchEventToEmbedder( |
| new GuestViewBase::Event(webview::kEventLoadRedirect, args.Pass())); |
| } |
| @@ -1190,7 +887,7 @@ void WebViewGuest::SizeChanged(const gfx::Size& old_size, |
| args->SetInteger(webview::kOldWidth, old_size.width()); |
| args->SetInteger(webview::kNewHeight, new_size.height()); |
| args->SetInteger(webview::kNewWidth, new_size.width()); |
| - DispatchEvent( |
| + DispatchEventToEmbedder( |
| new GuestViewBase::Event(webview::kEventSizeChanged, args.Pass())); |
| } |
| @@ -1198,17 +895,9 @@ void WebViewGuest::RequestMediaAccessPermission( |
| content::WebContents* source, |
| const content::MediaStreamRequest& request, |
| const content::MediaResponseCallback& callback) { |
| - base::DictionaryValue request_info; |
| - request_info.Set( |
| - guestview::kUrl, |
| - base::Value::CreateStringValue(request.security_origin.spec())); |
| - RequestPermission(WEB_VIEW_PERMISSION_TYPE_MEDIA, |
| - request_info, |
| - base::Bind(&WebViewGuest::OnWebViewMediaPermissionResponse, |
| - base::Unretained(this), |
| - request, |
| - callback), |
| - false /* allowed_by_default */); |
| + web_view_permission_helper_->RequestMediaAccessPermission(source, |
| + request, |
| + callback); |
| } |
| void WebViewGuest::CanDownload( |
| @@ -1216,39 +905,20 @@ void WebViewGuest::CanDownload( |
| const GURL& url, |
| const std::string& request_method, |
| const base::Callback<void(bool)>& callback) { |
| - base::DictionaryValue request_info; |
| - request_info.Set( |
| - guestview::kUrl, |
| - base::Value::CreateStringValue(url.spec())); |
| - RequestPermission( |
| - WEB_VIEW_PERMISSION_TYPE_DOWNLOAD, |
| - request_info, |
| - base::Bind(&WebViewGuest::OnWebViewDownloadPermissionResponse, |
| - base::Unretained(this), |
| - callback), |
| - false /* allowed_by_default */); |
| + web_view_permission_helper_->CanDownload(render_view_host, |
| + url, |
|
Fady Samuel
2014/07/07 15:01:52
Fix alignment.
Xi Han
2014/07/08 15:59:13
Done.
|
| + request_method, |
| + callback); |
| } |
| void WebViewGuest::RequestPointerLockPermission( |
| bool user_gesture, |
| bool last_unlocked_by_target, |
| const base::Callback<void(bool)>& callback) { |
| - base::DictionaryValue request_info; |
| - request_info.Set(guestview::kUserGesture, |
| - base::Value::CreateBooleanValue(user_gesture)); |
| - request_info.Set(webview::kLastUnlockedBySelf, |
| - base::Value::CreateBooleanValue(last_unlocked_by_target)); |
| - request_info.Set(guestview::kUrl, |
| - base::Value::CreateStringValue( |
| - guest_web_contents()->GetLastCommittedURL().spec())); |
| - |
| - RequestPermission( |
| - WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK, |
| - request_info, |
| - base::Bind(&WebViewGuest::OnWebViewPointerLockPermissionResponse, |
| - base::Unretained(this), |
| - callback), |
| - false /* allowed_by_default */); |
| + web_view_permission_helper_->RequestPointerLockPermission( |
| + user_gesture, |
| + last_unlocked_by_target, |
| + callback); |
| } |
| void WebViewGuest::WillAttachToEmbedder() { |
| @@ -1342,65 +1012,6 @@ void WebViewGuest::InjectChromeVoxIfNeeded( |
| #endif |
| } |
| -int WebViewGuest::RemoveBridgeID(int bridge_id) { |
| - std::map<int, int>::iterator bridge_itr = |
| - bridge_id_to_request_id_map_.find(bridge_id); |
| - if (bridge_itr == bridge_id_to_request_id_map_.end()) |
| - return webview::kInvalidPermissionRequestID; |
| - |
| - int request_id = bridge_itr->second; |
| - bridge_id_to_request_id_map_.erase(bridge_itr); |
| - return request_id; |
| -} |
| - |
| -int WebViewGuest::RequestPermission( |
| - WebViewPermissionType permission_type, |
| - const base::DictionaryValue& request_info, |
| - const PermissionResponseCallback& callback, |
| - bool allowed_by_default) { |
| - // If there are too many pending permission requests then reject this request. |
| - if (pending_permission_requests_.size() >= |
| - webview::kMaxOutstandingPermissionRequests) { |
| - // Let the stack unwind before we deny the permission request so that |
| - // objects held by the permission request are not destroyed immediately |
| - // after creation. This is to allow those same objects to be accessed again |
| - // in the same scope without fear of use after freeing. |
| - base::MessageLoop::current()->PostTask( |
| - FROM_HERE, |
| - base::Bind(&PermissionResponseCallback::Run, |
| - base::Owned(new PermissionResponseCallback(callback)), |
| - allowed_by_default, |
| - std::string())); |
| - return webview::kInvalidPermissionRequestID; |
| - } |
| - |
| - int request_id = next_permission_request_id_++; |
| - pending_permission_requests_[request_id] = |
| - PermissionResponseInfo(callback, permission_type, allowed_by_default); |
| - scoped_ptr<base::DictionaryValue> args(request_info.DeepCopy()); |
| - args->SetInteger(webview::kRequestId, request_id); |
| - switch (permission_type) { |
| - case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: { |
| - DispatchEvent( |
| - new GuestViewBase::Event(webview::kEventNewWindow, args.Pass())); |
| - break; |
| - } |
| - case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: { |
| - DispatchEvent( |
| - new GuestViewBase::Event(webview::kEventDialog, args.Pass())); |
| - break; |
| - } |
| - default: { |
| - args->SetString(webview::kPermission, |
| - PermissionTypeToString(permission_type)); |
| - DispatchEvent(new GuestViewBase::Event(webview::kEventPermissionRequest, |
| - args.Pass())); |
| - break; |
| - } |
| - } |
| - return request_id; |
| -} |
| - |
| bool WebViewGuest::HandleKeyboardShortcuts( |
| const content::NativeWebKeyboardEvent& event) { |
| if (event.type != blink::WebInputEvent::RawKeyDown) |
| @@ -1441,23 +1052,6 @@ bool WebViewGuest::HandleKeyboardShortcuts( |
| return false; |
| } |
| -WebViewGuest::PermissionResponseInfo::PermissionResponseInfo() |
| - : permission_type(WEB_VIEW_PERMISSION_TYPE_UNKNOWN), |
| - allowed_by_default(false) { |
| -} |
| - |
| -WebViewGuest::PermissionResponseInfo::PermissionResponseInfo( |
| - const PermissionResponseCallback& callback, |
| - WebViewPermissionType permission_type, |
| - bool allowed_by_default) |
| - : callback(callback), |
| - permission_type(permission_type), |
| - allowed_by_default(allowed_by_default) { |
| -} |
| - |
| -WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { |
| -} |
| - |
| void WebViewGuest::ShowContextMenu(int request_id, |
| const MenuItemVector* items) { |
| if (!pending_menu_.get()) |
| @@ -1490,7 +1084,7 @@ void WebViewGuest::SetZoom(double zoom_factor) { |
| scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| args->SetDouble(webview::kOldZoomFactor, current_zoom_factor_); |
| args->SetDouble(webview::kNewZoomFactor, zoom_factor); |
| - DispatchEvent( |
| + DispatchEventToEmbedder( |
| new GuestViewBase::Event(webview::kEventZoomChange, args.Pass())); |
| current_zoom_factor_ = zoom_factor; |
| @@ -1606,12 +1200,13 @@ void WebViewGuest::RequestNewWindowPermission( |
| base::Value::CreateStringValue( |
| WindowOpenDispositionToString(disposition))); |
| - RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, |
| - request_info, |
| - base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, |
| - base::Unretained(this), |
| - guest->GetGuestInstanceID()), |
| - false /* allowed_by_default */); |
| + web_view_permission_helper_-> |
| + RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, |
| + request_info, |
| + base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, |
| + base::Unretained(this), |
| + guest->GetGuestInstanceID()), |
| + false /* allowed_by_default */); |
| } |
| void WebViewGuest::DestroyUnattachedWindows() { |