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 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 if (frame_id == main_frame_id_) | 679 if (frame_id == main_frame_id_) |
670 InjectChromeVoxIfNeeded(render_view_host); | 680 InjectChromeVoxIfNeeded(render_view_host); |
671 } | 681 } |
672 | 682 |
673 void WebViewGuest::DidStopLoading(content::RenderViewHost* render_view_host) { | 683 void WebViewGuest::DidStopLoading(content::RenderViewHost* render_view_host) { |
674 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 684 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
675 DispatchEvent(new GuestView::Event(webview::kEventLoadStop, args.Pass())); | 685 DispatchEvent(new GuestView::Event(webview::kEventLoadStop, args.Pass())); |
676 } | 686 } |
677 | 687 |
678 void WebViewGuest::WebContentsDestroyed(WebContents* web_contents) { | 688 void WebViewGuest::WebContentsDestroyed(WebContents* web_contents) { |
| 689 // Clean up custom context menu items for this guest. |
| 690 extensions::MenuManager* menu_manager = extensions::MenuManager::Get( |
| 691 Profile::FromBrowserContext(browser_context())); |
| 692 menu_manager->RemoveAllContextItems(extensions::MenuItem::ExtensionKey( |
| 693 embedder_extension_id(), view_instance_id())); |
| 694 |
679 RemoveWebViewFromExtensionRendererState(web_contents); | 695 RemoveWebViewFromExtensionRendererState(web_contents); |
680 } | 696 } |
681 | 697 |
682 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { | 698 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { |
683 content::NavigationController& controller = | 699 content::NavigationController& controller = |
684 guest_web_contents()->GetController(); | 700 guest_web_contents()->GetController(); |
685 content::NavigationEntry* entry = controller.GetVisibleEntry(); | 701 content::NavigationEntry* entry = controller.GetVisibleEntry(); |
686 if (!entry) | 702 if (!entry) |
687 return; | 703 return; |
688 entry->SetIsOverridingUserAgent(!user_agent.empty()); | 704 entry->SetIsOverridingUserAgent(!user_agent.empty()); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 const PermissionResponseCallback& callback, | 826 const PermissionResponseCallback& callback, |
811 BrowserPluginPermissionType permission_type, | 827 BrowserPluginPermissionType permission_type, |
812 bool allowed_by_default) | 828 bool allowed_by_default) |
813 : callback(callback), | 829 : callback(callback), |
814 permission_type(permission_type), | 830 permission_type(permission_type), |
815 allowed_by_default(allowed_by_default) { | 831 allowed_by_default(allowed_by_default) { |
816 } | 832 } |
817 | 833 |
818 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { | 834 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { |
819 } | 835 } |
OLD | NEW |