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

Side by Side Diff: chrome/browser/extensions/api/webview/webview_api.cc

Issue 186213003: <webview>: Context menu API implementation CL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync @tott Created 6 years, 9 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/extensions/api/webview/webview_api.h" 5 #include "chrome/browser/extensions/api/webview/webview_api.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/extensions/api/browsing_data/browsing_data_api.h" 8 #include "chrome/browser/extensions/api/browsing_data/browsing_data_api.h"
9 #include "chrome/browser/extensions/api/context_menus/context_menus_api.h"
9 #include "chrome/browser/extensions/api/context_menus/context_menus_api_helpers. h" 10 #include "chrome/browser/extensions/api/context_menus/context_menus_api_helpers. h"
10 #include "chrome/browser/extensions/tab_helper.h" 11 #include "chrome/browser/extensions/tab_helper.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/common/extensions/api/webview.h" 13 #include "chrome/common/extensions/api/webview.h"
13 #include "content/public/browser/render_process_host.h" 14 #include "content/public/browser/render_process_host.h"
14 #include "content/public/browser/render_view_host.h" 15 #include "content/public/browser/render_view_host.h"
15 #include "content/public/browser/storage_partition.h" 16 #include "content/public/browser/storage_partition.h"
16 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
17 #include "content/public/common/stop_find_action.h" 18 #include "content/public/common/stop_find_action.h"
18 #include "extensions/common/error_utils.h" 19 #include "extensions/common/error_utils.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 59
59 // TODO(lazyboy): Add checks similar to 60 // TODO(lazyboy): Add checks similar to
60 // WebviewExtensionFunction::RunImplSafe(WebViewGuest*). 61 // WebviewExtensionFunction::RunImplSafe(WebViewGuest*).
61 bool WebviewContextMenusCreateFunction::RunImpl() { 62 bool WebviewContextMenusCreateFunction::RunImpl() {
62 scoped_ptr<webview::ContextMenusCreate::Params> params( 63 scoped_ptr<webview::ContextMenusCreate::Params> params(
63 webview::ContextMenusCreate::Params::Create(*args_)); 64 webview::ContextMenusCreate::Params::Create(*args_));
64 EXTENSION_FUNCTION_VALIDATE(params.get()); 65 EXTENSION_FUNCTION_VALIDATE(params.get());
65 66
66 MenuItem::Id id( 67 MenuItem::Id id(
67 Profile::FromBrowserContext(browser_context())->IsOffTheRecord(), 68 Profile::FromBrowserContext(browser_context())->IsOffTheRecord(),
68 extension_id()); 69 MenuItem::ExtensionKey(extension_id(), params->instance_id));
69 70
70 if (params->create_properties.id.get()) { 71 if (params->create_properties.id.get()) {
71 id.string_uid = *params->create_properties.id; 72 id.string_uid = *params->create_properties.id;
72 } else { 73 } else {
73 // The Generated Id is added by webview_custom_bindings.js. 74 // The Generated Id is added by webview_custom_bindings.js.
74 base::DictionaryValue* properties = NULL; 75 base::DictionaryValue* properties = NULL;
75 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &properties)); 76 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &properties));
76 EXTENSION_FUNCTION_VALIDATE( 77 EXTENSION_FUNCTION_VALIDATE(
77 properties->GetInteger(helpers::kGeneratedIdKey, &id.uid)); 78 properties->GetInteger(helpers::kGeneratedIdKey, &id.uid));
78 } 79 }
79 80
80 // TODO(lazyboy): Implement. 81 bool success = extensions::context_menus_api_helpers::CreateMenuItem(
81 SendResponse(false); 82 params->create_properties,
82 return false; 83 Profile::FromBrowserContext(browser_context()),
84 GetExtension(),
85 id,
86 &error_);
87
88 SendResponse(success);
89 return success;
83 } 90 }
84 91
85 bool WebviewContextMenusUpdateFunction::RunImpl() { 92 bool WebviewContextMenusUpdateFunction::RunImpl() {
86 scoped_ptr<webview::ContextMenusUpdate::Params> params( 93 scoped_ptr<webview::ContextMenusUpdate::Params> params(
87 webview::ContextMenusUpdate::Params::Create(*args_)); 94 webview::ContextMenusUpdate::Params::Create(*args_));
88 EXTENSION_FUNCTION_VALIDATE(params.get()); 95 EXTENSION_FUNCTION_VALIDATE(params.get());
89 96
90 Profile* profile = Profile::FromBrowserContext(browser_context()); 97 Profile* profile = Profile::FromBrowserContext(browser_context());
91 MenuItem::Id item_id(profile->IsOffTheRecord(), extension_id()); 98 MenuItem::Id item_id(
99 profile->IsOffTheRecord(),
100 MenuItem::ExtensionKey(extension_id(), params->instance_id));
92 101
93 if (params->id.as_string) 102 if (params->id.as_string)
94 item_id.string_uid = *params->id.as_string; 103 item_id.string_uid = *params->id.as_string;
95 else if (params->id.as_integer) 104 else if (params->id.as_integer)
96 item_id.uid = *params->id.as_integer; 105 item_id.uid = *params->id.as_integer;
97 else 106 else
98 NOTREACHED(); 107 NOTREACHED();
99 108
100 // TODO(lazyboy): Implement. 109 bool success = extensions::context_menus_api_helpers::UpdateMenuItem(
101 SendResponse(false); 110 params->update_properties, profile, GetExtension(), item_id, &error_);
102 return false; 111 SendResponse(success);
112 return success;
103 } 113 }
104 114
105 bool WebviewContextMenusRemoveFunction::RunImpl() { 115 bool WebviewContextMenusRemoveFunction::RunImpl() {
106 scoped_ptr<webview::ContextMenusRemove::Params> params( 116 scoped_ptr<webview::ContextMenusRemove::Params> params(
107 webview::ContextMenusRemove::Params::Create(*args_)); 117 webview::ContextMenusRemove::Params::Create(*args_));
108 EXTENSION_FUNCTION_VALIDATE(params.get()); 118 EXTENSION_FUNCTION_VALIDATE(params.get());
109 119
110 // TODO(lazyboy): Implement. 120 MenuManager* menu_manager =
111 SendResponse(false); 121 MenuManager::Get(Profile::FromBrowserContext(browser_context()));
112 return false; 122
123 MenuItem::Id id(
124 Profile::FromBrowserContext(browser_context())->IsOffTheRecord(),
125 MenuItem::ExtensionKey(extension_id(), params->instance_id));
126
127 if (params->menu_item_id.as_string) {
128 id.string_uid = *params->menu_item_id.as_string;
129 } else if (params->menu_item_id.as_integer) {
130 id.uid = *params->menu_item_id.as_integer;
131 } else {
132 NOTREACHED();
133 }
134
135 bool success = true;
136 MenuItem* item = menu_manager->GetItemById(id);
137 // Ensure one <webview> can't remove another's menu items.
138 if (!item || item->id().extension_key != id.extension_key) {
139 error_ = ErrorUtils::FormatErrorMessage(
140 context_menus_api_helpers::kCannotFindItemError,
141 context_menus_api_helpers::GetIDString(id));
142 success = false;
143 } else if (!menu_manager->RemoveContextMenuItem(id)) {
144 success = false;
145 }
146
147 SendResponse(success);
148 return success;
113 } 149 }
114 150
115 bool WebviewContextMenusRemoveAllFunction::RunImpl() { 151 bool WebviewContextMenusRemoveAllFunction::RunImpl() {
116 scoped_ptr<webview::ContextMenusRemoveAll::Params> params( 152 scoped_ptr<webview::ContextMenusRemoveAll::Params> params(
117 webview::ContextMenusRemoveAll::Params::Create(*args_)); 153 webview::ContextMenusRemoveAll::Params::Create(*args_));
118 EXTENSION_FUNCTION_VALIDATE(params.get()); 154 EXTENSION_FUNCTION_VALIDATE(params.get());
119 155
120 // TODO(lazyboy): Implement. 156 MenuManager* menu_manager =
121 SendResponse(false); 157 MenuManager::Get(Profile::FromBrowserContext(browser_context()));
122 return false; 158
159 int webview_instance_id = params->instance_id;
160 menu_manager->RemoveAllContextItems(
161 MenuItem::ExtensionKey(GetExtension()->id(), webview_instance_id));
162 SendResponse(true);
163 return true;
123 } 164 }
124 165
125 WebviewClearDataFunction::WebviewClearDataFunction() 166 WebviewClearDataFunction::WebviewClearDataFunction()
126 : remove_mask_(0), bad_message_(false) {} 167 : remove_mask_(0), bad_message_(false) {}
127 168
128 WebviewClearDataFunction::~WebviewClearDataFunction() {} 169 WebviewClearDataFunction::~WebviewClearDataFunction() {}
129 170
130 // Parses the |dataToRemove| argument to generate the remove mask. Sets 171 // Parses the |dataToRemove| argument to generate the remove mask. Sets
131 // |bad_message_| (like EXTENSION_FUNCTION_VALIDATE would if this were a bool 172 // |bad_message_| (like EXTENSION_FUNCTION_VALIDATE would if this were a bool
132 // method) if 'dataToRemove' is not present. 173 // method) if 'dataToRemove' is not present.
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 528
488 WebviewTerminateFunction::~WebviewTerminateFunction() { 529 WebviewTerminateFunction::~WebviewTerminateFunction() {
489 } 530 }
490 531
491 bool WebviewTerminateFunction::RunImplSafe(WebViewGuest* guest) { 532 bool WebviewTerminateFunction::RunImplSafe(WebViewGuest* guest) {
492 guest->Terminate(); 533 guest->Terminate();
493 return true; 534 return true;
494 } 535 }
495 536
496 } // namespace extensions 537 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698