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

Side by Side Diff: chrome/browser/extensions/api/guest_view/guest_view_internal_api.cc

Issue 378873002: Move permission check from GuestViewInternal to derived GuestView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@app_view_meat
Patch Set: Diff against tip of tree Created 6 years, 5 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
« no previous file with comments | « no previous file | chrome/browser/guest_view/app_view/app_view_guest.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/extensions/api/guest_view/guest_view_internal_api.h" 5 #include "chrome/browser/extensions/api/guest_view/guest_view_internal_api.h"
6 6
7 #include "chrome/browser/guest_view/guest_view_base.h" 7 #include "chrome/browser/guest_view/guest_view_base.h"
8 #include "chrome/browser/guest_view/guest_view_manager.h" 8 #include "chrome/browser/guest_view/guest_view_manager.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/extensions/api/guest_view_internal.h" 10 #include "chrome/common/extensions/api/guest_view_internal.h"
11 #include "content/public/browser/render_process_host.h" 11 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/render_view_host.h" 12 #include "content/public/browser/render_view_host.h"
13 #include "extensions/common/permissions/permissions_data.h" 13 #include "extensions/common/permissions/permissions_data.h"
14 14
15 namespace {
16 const char* kPermissionRequiredError =
17 "\"webview\" or \"appview\" permission is required for allocating "
18 "instance ID.";
19 } // namespace
20
21 namespace extensions { 15 namespace extensions {
22 16
23 GuestViewInternalCreateGuestFunction:: 17 GuestViewInternalCreateGuestFunction::
24 GuestViewInternalCreateGuestFunction() { 18 GuestViewInternalCreateGuestFunction() {
25 } 19 }
26 20
27 bool GuestViewInternalCreateGuestFunction::RunAsync() { 21 bool GuestViewInternalCreateGuestFunction::RunAsync() {
28 std::string view_type; 22 std::string view_type;
29 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &view_type)); 23 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &view_type));
30 24
31 base::DictionaryValue* create_params; 25 base::DictionaryValue* create_params;
32 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &create_params)); 26 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &create_params));
33 27
34 const PermissionsData* permissions_data = GetExtension()->permissions_data();
35 if (!permissions_data->HasAPIPermission(APIPermission::kWebView) &&
36 !permissions_data->HasAPIPermission(APIPermission::kAppView)) {
37 LOG(ERROR) << kPermissionRequiredError;
38 error_ = kPermissionRequiredError;
39 SendResponse(false);
40 return true;
41 }
42
43 GuestViewManager* guest_view_manager = 28 GuestViewManager* guest_view_manager =
44 GuestViewManager::FromBrowserContext(browser_context()); 29 GuestViewManager::FromBrowserContext(browser_context());
45 30
46 GuestViewManager::WebContentsCreatedCallback callback = 31 GuestViewManager::WebContentsCreatedCallback callback =
47 base::Bind(&GuestViewInternalCreateGuestFunction::CreateGuestCallback, 32 base::Bind(&GuestViewInternalCreateGuestFunction::CreateGuestCallback,
48 this); 33 this);
49 guest_view_manager->CreateGuest(view_type, 34 guest_view_manager->CreateGuest(view_type,
50 extension_id(), 35 extension_id(),
51 render_view_host()->GetProcess()->GetID(), 36 render_view_host()->GetProcess()->GetID(),
52 *create_params, 37 *create_params,
53 callback); 38 callback);
54 39
55 return true; 40 return true;
56 } 41 }
57 42
58 void GuestViewInternalCreateGuestFunction::CreateGuestCallback( 43 void GuestViewInternalCreateGuestFunction::CreateGuestCallback(
59 content::WebContents* guest_web_contents) { 44 content::WebContents* guest_web_contents) {
60 int guest_instance_id = 0; 45 int guest_instance_id = 0;
61 if (guest_web_contents) { 46 if (guest_web_contents) {
62 GuestViewBase* guest = GuestViewBase::FromWebContents(guest_web_contents); 47 GuestViewBase* guest = GuestViewBase::FromWebContents(guest_web_contents);
63 guest_instance_id = guest->GetGuestInstanceID(); 48 guest_instance_id = guest->GetGuestInstanceID();
64 } 49 }
65 SetResult(base::Value::CreateIntegerValue(guest_instance_id)); 50 SetResult(base::Value::CreateIntegerValue(guest_instance_id));
66 SendResponse(true); 51 SendResponse(true);
67 } 52 }
68 53
69 } // namespace extensions 54 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/guest_view/app_view/app_view_guest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698