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

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: again 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" 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
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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL(); 560 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL();
568 const std::string storage_partition_id = 561 const std::string storage_partition_id =
569 GetStoragePartitionIdFromSiteURL(site_url); 562 GetStoragePartitionIdFromSiteURL(site_url);
570 base::DictionaryValue create_params; 563 base::DictionaryValue create_params;
571 create_params.SetString(webview::kStoragePartitionId, storage_partition_id); 564 create_params.SetString(webview::kStoragePartitionId, storage_partition_id);
572 565
573 guest_manager->CreateGuest( 566 guest_manager->CreateGuest(
574 WebViewGuest::Type, 567 WebViewGuest::Type,
575 embedder_extension_id(), 568 embedder_extension_id(),
576 embedder_web_contents()->GetRenderProcessHost()->GetID(), 569 embedder_web_contents()->GetRenderProcessHost()->GetID(),
570 embedder_web_contents(),
577 create_params, 571 create_params,
578 base::Bind(&WebViewGuest::NewGuestWebViewCallback, 572 base::Bind(&WebViewGuest::NewGuestWebViewCallback,
579 base::Unretained(this), params)); 573 base::Unretained(this),
574 params));
580 } 575 }
581 576
582 void WebViewGuest::NewGuestWebViewCallback( 577 void WebViewGuest::NewGuestWebViewCallback(
583 const content::OpenURLParams& params, 578 const content::OpenURLParams& params,
584 content::WebContents* guest_web_contents) { 579 content::WebContents* guest_web_contents) {
585 WebViewGuest* new_guest = WebViewGuest::FromWebContents(guest_web_contents); 580 WebViewGuest* new_guest = WebViewGuest::FromWebContents(guest_web_contents);
586 new_guest->SetOpener(this); 581 new_guest->SetOpener(this);
587 582
588 // Take ownership of |new_guest|. 583 // Take ownership of |new_guest|.
589 pending_new_windows_.insert( 584 pending_new_windows_.insert(
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 bool allow, 1262 bool allow,
1268 const std::string& user_input) { 1263 const std::string& user_input) {
1269 WebViewGuest* guest = 1264 WebViewGuest* guest =
1270 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); 1265 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id);
1271 if (!guest) 1266 if (!guest)
1272 return; 1267 return;
1273 1268
1274 if (!allow) 1269 if (!allow)
1275 guest->Destroy(); 1270 guest->Destroy();
1276 } 1271 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698