OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/guest_view/web_view/web_view_guest.h" | 5 #include "chrome/browser/guest_view/web_view/web_view_guest.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 #include "content/public/browser/site_instance.h" | 41 #include "content/public/browser/site_instance.h" |
42 #include "content/public/browser/storage_partition.h" | 42 #include "content/public/browser/storage_partition.h" |
43 #include "content/public/browser/user_metrics.h" | 43 #include "content/public/browser/user_metrics.h" |
44 #include "content/public/browser/web_contents.h" | 44 #include "content/public/browser/web_contents.h" |
45 #include "content/public/browser/web_contents_delegate.h" | 45 #include "content/public/browser/web_contents_delegate.h" |
46 #include "content/public/common/media_stream_request.h" | 46 #include "content/public/common/media_stream_request.h" |
47 #include "content/public/common/page_zoom.h" | 47 #include "content/public/common/page_zoom.h" |
48 #include "content/public/common/result_codes.h" | 48 #include "content/public/common/result_codes.h" |
49 #include "content/public/common/stop_find_action.h" | 49 #include "content/public/common/stop_find_action.h" |
50 #include "content/public/common/url_constants.h" | 50 #include "content/public/common/url_constants.h" |
51 #include "extensions/browser/extension_registry.h" | |
52 #include "extensions/browser/extension_system.h" | 51 #include "extensions/browser/extension_system.h" |
53 #include "extensions/common/constants.h" | 52 #include "extensions/common/constants.h" |
54 #include "extensions/common/permissions/permissions_data.h" | 53 #include "extensions/common/features/feature.h" |
| 54 #include "extensions/common/features/feature_provider.h" |
55 #include "ipc/ipc_message_macros.h" | 55 #include "ipc/ipc_message_macros.h" |
56 #include "net/base/escape.h" | 56 #include "net/base/escape.h" |
57 #include "net/base/net_errors.h" | 57 #include "net/base/net_errors.h" |
58 #include "third_party/WebKit/public/web/WebFindOptions.h" | 58 #include "third_party/WebKit/public/web/WebFindOptions.h" |
59 #include "ui/base/models/simple_menu_model.h" | 59 #include "ui/base/models/simple_menu_model.h" |
60 | 60 |
61 #if defined(ENABLE_PRINTING) | 61 #if defined(ENABLE_PRINTING) |
62 #if defined(ENABLE_FULL_PRINTING) | 62 #if defined(ENABLE_FULL_PRINTING) |
63 #include "chrome/browser/printing/print_preview_message_handler.h" | 63 #include "chrome/browser/printing/print_preview_message_handler.h" |
64 #include "chrome/browser/printing/print_view_manager.h" | 64 #include "chrome/browser/printing/print_view_manager.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 // TODO(lazyboy): We need to expose some kind of enum equivalent of | 219 // TODO(lazyboy): We need to expose some kind of enum equivalent of |
220 // |command_id| instead of plain integers. | 220 // |command_id| instead of plain integers. |
221 item_value->SetInteger(webview::kMenuItemCommandId, | 221 item_value->SetInteger(webview::kMenuItemCommandId, |
222 menu_model.GetCommandIdAt(i)); | 222 menu_model.GetCommandIdAt(i)); |
223 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i)); | 223 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i)); |
224 items->Append(item_value); | 224 items->Append(item_value); |
225 } | 225 } |
226 return items.Pass(); | 226 return items.Pass(); |
227 } | 227 } |
228 | 228 |
229 bool WebViewGuest::CanEmbedderUseGuestView( | 229 extensions::Feature* WebViewGuest::GetFeature() { |
230 const std::string& embedder_extension_id) { | 230 return extensions::FeatureProvider::GetAPIFeatures()->GetFeature( |
231 const extensions::Extension* embedder_extension = | 231 "webViewInternal"); |
232 extensions::ExtensionRegistry::Get(browser_context()) | |
233 ->enabled_extensions() | |
234 .GetByID(embedder_extension_id); | |
235 if (!embedder_extension) | |
236 return false; | |
237 return embedder_extension->permissions_data()->HasAPIPermission( | |
238 extensions::APIPermission::kWebView); | |
239 } | 232 } |
240 | 233 |
241 void WebViewGuest::CreateWebContents( | 234 void WebViewGuest::CreateWebContents( |
242 const std::string& embedder_extension_id, | 235 const std::string& embedder_extension_id, |
243 int embedder_render_process_id, | 236 int embedder_render_process_id, |
244 const base::DictionaryValue& create_params, | 237 const base::DictionaryValue& create_params, |
245 const WebContentsCreatedCallback& callback) { | 238 const WebContentsCreatedCallback& callback) { |
246 content::RenderProcessHost* embedder_render_process_host = | 239 content::RenderProcessHost* embedder_render_process_host = |
247 content::RenderProcessHost::FromID(embedder_render_process_id); | 240 content::RenderProcessHost::FromID(embedder_render_process_id); |
248 std::string storage_partition_id; | 241 std::string storage_partition_id; |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL(); | 537 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL(); |
545 const std::string storage_partition_id = | 538 const std::string storage_partition_id = |
546 GetStoragePartitionIdFromSiteURL(site_url); | 539 GetStoragePartitionIdFromSiteURL(site_url); |
547 base::DictionaryValue create_params; | 540 base::DictionaryValue create_params; |
548 create_params.SetString(webview::kStoragePartitionId, storage_partition_id); | 541 create_params.SetString(webview::kStoragePartitionId, storage_partition_id); |
549 | 542 |
550 guest_manager->CreateGuest( | 543 guest_manager->CreateGuest( |
551 WebViewGuest::Type, | 544 WebViewGuest::Type, |
552 embedder_extension_id(), | 545 embedder_extension_id(), |
553 embedder_web_contents()->GetRenderProcessHost()->GetID(), | 546 embedder_web_contents()->GetRenderProcessHost()->GetID(), |
| 547 embedder_web_contents(), |
554 create_params, | 548 create_params, |
555 base::Bind(&WebViewGuest::NewGuestWebViewCallback, | 549 base::Bind(&WebViewGuest::NewGuestWebViewCallback, |
556 base::Unretained(this), params)); | 550 base::Unretained(this), |
| 551 params)); |
557 } | 552 } |
558 | 553 |
559 void WebViewGuest::NewGuestWebViewCallback( | 554 void WebViewGuest::NewGuestWebViewCallback( |
560 const content::OpenURLParams& params, | 555 const content::OpenURLParams& params, |
561 content::WebContents* guest_web_contents) { | 556 content::WebContents* guest_web_contents) { |
562 WebViewGuest* new_guest = WebViewGuest::FromWebContents(guest_web_contents); | 557 WebViewGuest* new_guest = WebViewGuest::FromWebContents(guest_web_contents); |
563 new_guest->SetOpener(this); | 558 new_guest->SetOpener(this); |
564 | 559 |
565 // Take ownership of |new_guest|. | 560 // Take ownership of |new_guest|. |
566 pending_new_windows_.insert( | 561 pending_new_windows_.insert( |
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1239 bool allow, | 1234 bool allow, |
1240 const std::string& user_input) { | 1235 const std::string& user_input) { |
1241 WebViewGuest* guest = | 1236 WebViewGuest* guest = |
1242 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1237 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
1243 if (!guest) | 1238 if (!guest) |
1244 return; | 1239 return; |
1245 | 1240 |
1246 if (!allow) | 1241 if (!allow) |
1247 guest->Destroy(); | 1242 guest->Destroy(); |
1248 } | 1243 } |
OLD | NEW |