Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: chrome/browser/guest_view/web_view/web_view_guest.cc

Issue 426593007: Refactor guest view availability to be API not permission based. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: MostLikelyContextType Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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"
55 #include "ipc/ipc_message_macros.h" 53 #include "ipc/ipc_message_macros.h"
56 #include "net/base/escape.h" 54 #include "net/base/escape.h"
57 #include "net/base/net_errors.h" 55 #include "net/base/net_errors.h"
58 #include "third_party/WebKit/public/web/WebFindOptions.h" 56 #include "third_party/WebKit/public/web/WebFindOptions.h"
59 #include "ui/base/models/simple_menu_model.h" 57 #include "ui/base/models/simple_menu_model.h"
60 58
61 #if defined(ENABLE_PRINTING) 59 #if defined(ENABLE_PRINTING)
62 #if defined(ENABLE_FULL_PRINTING) 60 #if defined(ENABLE_FULL_PRINTING)
63 #include "chrome/browser/printing/print_preview_message_handler.h" 61 #include "chrome/browser/printing/print_preview_message_handler.h"
64 #include "chrome/browser/printing/print_view_manager.h" 62 #include "chrome/browser/printing/print_view_manager.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 // TODO(lazyboy): We need to expose some kind of enum equivalent of 217 // TODO(lazyboy): We need to expose some kind of enum equivalent of
220 // |command_id| instead of plain integers. 218 // |command_id| instead of plain integers.
221 item_value->SetInteger(webview::kMenuItemCommandId, 219 item_value->SetInteger(webview::kMenuItemCommandId,
222 menu_model.GetCommandIdAt(i)); 220 menu_model.GetCommandIdAt(i));
223 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i)); 221 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i));
224 items->Append(item_value); 222 items->Append(item_value);
225 } 223 }
226 return items.Pass(); 224 return items.Pass();
227 } 225 }
228 226
229 bool WebViewGuest::CanEmbedderUseGuestView( 227 const char* WebViewGuest::GetAPINamespace() {
230 const std::string& embedder_extension_id) { 228 return webview::kAPINamespace;
231 const extensions::Extension* embedder_extension =
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 } 229 }
240 230
241 void WebViewGuest::CreateWebContents( 231 void WebViewGuest::CreateWebContents(
242 const std::string& embedder_extension_id, 232 const std::string& embedder_extension_id,
243 int embedder_render_process_id, 233 int embedder_render_process_id,
244 const base::DictionaryValue& create_params, 234 const base::DictionaryValue& create_params,
245 const WebContentsCreatedCallback& callback) { 235 const WebContentsCreatedCallback& callback) {
246 content::RenderProcessHost* embedder_render_process_host = 236 content::RenderProcessHost* embedder_render_process_host =
247 content::RenderProcessHost::FromID(embedder_render_process_id); 237 content::RenderProcessHost::FromID(embedder_render_process_id);
248 std::string storage_partition_id; 238 std::string storage_partition_id;
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 GuestViewManager::FromBrowserContext(browser_context()); 553 GuestViewManager::FromBrowserContext(browser_context());
564 // Set the attach params to use the same partition as the opener. 554 // Set the attach params to use the same partition as the opener.
565 // We pull the partition information from the site's URL, which is of the 555 // We pull the partition information from the site's URL, which is of the
566 // form guest://site/{persist}?{partition_name}. 556 // form guest://site/{persist}?{partition_name}.
567 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL(); 557 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL();
568 const std::string storage_partition_id = 558 const std::string storage_partition_id =
569 GetStoragePartitionIdFromSiteURL(site_url); 559 GetStoragePartitionIdFromSiteURL(site_url);
570 base::DictionaryValue create_params; 560 base::DictionaryValue create_params;
571 create_params.SetString(webview::kStoragePartitionId, storage_partition_id); 561 create_params.SetString(webview::kStoragePartitionId, storage_partition_id);
572 562
573 guest_manager->CreateGuest( 563 guest_manager->CreateGuest(WebViewGuest::Type,
574 WebViewGuest::Type, 564 embedder_extension_id(),
575 embedder_extension_id(), 565 embedder_web_contents(),
576 embedder_web_contents()->GetRenderProcessHost()->GetID(), 566 create_params,
577 create_params, 567 base::Bind(&WebViewGuest::NewGuestWebViewCallback,
578 base::Bind(&WebViewGuest::NewGuestWebViewCallback, 568 base::Unretained(this),
579 base::Unretained(this), params)); 569 params));
580 } 570 }
581 571
582 void WebViewGuest::NewGuestWebViewCallback( 572 void WebViewGuest::NewGuestWebViewCallback(
583 const content::OpenURLParams& params, 573 const content::OpenURLParams& params,
584 content::WebContents* guest_web_contents) { 574 content::WebContents* guest_web_contents) {
585 WebViewGuest* new_guest = WebViewGuest::FromWebContents(guest_web_contents); 575 WebViewGuest* new_guest = WebViewGuest::FromWebContents(guest_web_contents);
586 new_guest->SetOpener(this); 576 new_guest->SetOpener(this);
587 577
588 // Take ownership of |new_guest|. 578 // Take ownership of |new_guest|.
589 pending_new_windows_.insert( 579 pending_new_windows_.insert(
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 bool allow, 1252 bool allow,
1263 const std::string& user_input) { 1253 const std::string& user_input) {
1264 WebViewGuest* guest = 1254 WebViewGuest* guest =
1265 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); 1255 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id);
1266 if (!guest) 1256 if (!guest)
1267 return; 1257 return;
1268 1258
1269 if (!allow) 1259 if (!allow)
1270 guest->Destroy(); 1260 guest->Destroy();
1271 } 1261 }
OLDNEW
« no previous file with comments | « chrome/browser/guest_view/web_view/web_view_guest.h ('k') | chrome/common/extensions/api/_api_features.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698