| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/guestview/webview/webview_guest.h" | 5 #include "chrome/browser/guestview/webview/webview_guest.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 9 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
| 10 #include "chrome/browser/extensions/api/webview/webview_api.h" | 10 #include "chrome/browser/extensions/api/webview/webview_api.h" |
| 11 #include "chrome/browser/extensions/extension_renderer_state.h" | 11 #include "chrome/browser/extensions/extension_renderer_state.h" |
| 12 #include "chrome/browser/extensions/extension_web_contents_observer.h" | 12 #include "chrome/browser/extensions/extension_web_contents_observer.h" |
| 13 #include "chrome/browser/extensions/menu_manager.h" |
| 13 #include "chrome/browser/extensions/script_executor.h" | 14 #include "chrome/browser/extensions/script_executor.h" |
| 14 #include "chrome/browser/favicon/favicon_tab_helper.h" | 15 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 15 #include "chrome/browser/guestview/guestview_constants.h" | 16 #include "chrome/browser/guestview/guestview_constants.h" |
| 16 #include "chrome/browser/guestview/webview/webview_constants.h" | 17 #include "chrome/browser/guestview/webview/webview_constants.h" |
| 17 #include "chrome/browser/guestview/webview/webview_permission_types.h" | 18 #include "chrome/browser/guestview/webview/webview_permission_types.h" |
| 18 #include "chrome/common/chrome_version_info.h" | 19 #include "chrome/common/chrome_version_info.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/native_web_keyboard_event.h" | 21 #include "content/public/browser/native_web_keyboard_event.h" |
| 21 #include "content/public/browser/navigation_entry.h" | 22 #include "content/public/browser/navigation_entry.h" |
| 22 #include "content/public/browser/notification_details.h" | 23 #include "content/public/browser/notification_details.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 return NULL; | 163 return NULL; |
| 163 return guest->AsWebView(); | 164 return guest->AsWebView(); |
| 164 } | 165 } |
| 165 | 166 |
| 166 // static | 167 // static |
| 167 WebViewGuest* WebViewGuest::FromWebContents(WebContents* contents) { | 168 WebViewGuest* WebViewGuest::FromWebContents(WebContents* contents) { |
| 168 GuestView* guest = GuestView::FromWebContents(contents); | 169 GuestView* guest = GuestView::FromWebContents(contents); |
| 169 return guest ? guest->AsWebView() : NULL; | 170 return guest ? guest->AsWebView() : NULL; |
| 170 } | 171 } |
| 171 | 172 |
| 173 // static. |
| 174 int WebViewGuest::GetViewInstanceId(WebContents* contents) { |
| 175 WebViewGuest* guest = FromWebContents(contents); |
| 176 if (!guest) |
| 177 return guestview::kInstanceIDNone; |
| 178 |
| 179 return guest->view_instance_id(); |
| 180 } |
| 181 |
| 172 // static | 182 // static |
| 173 void WebViewGuest::RecordUserInitiatedUMA(const PermissionResponseInfo& info, | 183 void WebViewGuest::RecordUserInitiatedUMA(const PermissionResponseInfo& info, |
| 174 bool allow) { | 184 bool allow) { |
| 175 if (allow) { | 185 if (allow) { |
| 176 // Note that |allow| == true means the embedder explicitly allowed the | 186 // Note that |allow| == true means the embedder explicitly allowed the |
| 177 // request. For some requests they might still fail. An example of such | 187 // request. For some requests they might still fail. An example of such |
| 178 // scenario would be: an embedder allows geolocation request but doesn't | 188 // scenario would be: an embedder allows geolocation request but doesn't |
| 179 // have geolocation access on its own. | 189 // have geolocation access on its own. |
| 180 switch (info.permission_type) { | 190 switch (info.permission_type) { |
| 181 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD: | 191 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD: |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 if (frame_id == main_frame_id_) | 685 if (frame_id == main_frame_id_) |
| 676 InjectChromeVoxIfNeeded(render_view_host); | 686 InjectChromeVoxIfNeeded(render_view_host); |
| 677 } | 687 } |
| 678 | 688 |
| 679 void WebViewGuest::DidStopLoading(content::RenderViewHost* render_view_host) { | 689 void WebViewGuest::DidStopLoading(content::RenderViewHost* render_view_host) { |
| 680 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 690 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 681 DispatchEvent(new GuestView::Event(webview::kEventLoadStop, args.Pass())); | 691 DispatchEvent(new GuestView::Event(webview::kEventLoadStop, args.Pass())); |
| 682 } | 692 } |
| 683 | 693 |
| 684 void WebViewGuest::WebContentsDestroyed(WebContents* web_contents) { | 694 void WebViewGuest::WebContentsDestroyed(WebContents* web_contents) { |
| 695 // Clean up custom context menu items for this guest. |
| 696 extensions::MenuManager* menu_manager = extensions::MenuManager::Get( |
| 697 Profile::FromBrowserContext(browser_context())); |
| 698 menu_manager->RemoveAllContextItems( |
| 699 extensions::MenuItem::ExtensionKey(extension_id(), view_instance_id())); |
| 700 |
| 685 RemoveWebViewFromExtensionRendererState(web_contents); | 701 RemoveWebViewFromExtensionRendererState(web_contents); |
| 686 } | 702 } |
| 687 | 703 |
| 688 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { | 704 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { |
| 689 content::NavigationController& controller = | 705 content::NavigationController& controller = |
| 690 guest_web_contents()->GetController(); | 706 guest_web_contents()->GetController(); |
| 691 content::NavigationEntry* entry = controller.GetVisibleEntry(); | 707 content::NavigationEntry* entry = controller.GetVisibleEntry(); |
| 692 if (!entry) | 708 if (!entry) |
| 693 return; | 709 return; |
| 694 entry->SetIsOverridingUserAgent(!user_agent.empty()); | 710 entry->SetIsOverridingUserAgent(!user_agent.empty()); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 const PermissionResponseCallback& callback, | 829 const PermissionResponseCallback& callback, |
| 814 BrowserPluginPermissionType permission_type, | 830 BrowserPluginPermissionType permission_type, |
| 815 bool allowed_by_default) | 831 bool allowed_by_default) |
| 816 : callback(callback), | 832 : callback(callback), |
| 817 permission_type(permission_type), | 833 permission_type(permission_type), |
| 818 allowed_by_default(allowed_by_default) { | 834 allowed_by_default(allowed_by_default) { |
| 819 } | 835 } |
| 820 | 836 |
| 821 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { | 837 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { |
| 822 } | 838 } |
| OLD | NEW |