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

Unified Diff: extensions/browser/api/web_view/web_view_internal_api.cc

Issue 541753004: Split web_view_internal_api and move part of it to extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: extensions/browser/api/web_view/web_view_internal_api.cc
diff --git a/chrome/browser/extensions/api/web_view/web_view_internal_api.cc b/extensions/browser/api/web_view/web_view_internal_api.cc
similarity index 53%
rename from chrome/browser/extensions/api/web_view/web_view_internal_api.cc
rename to extensions/browser/api/web_view/web_view_internal_api.cc
index b57a160aa2bf333d44824386940c9338152c33de..ce4a271396e248f0e3d899a8dbdbbbd03d937386 100644
--- a/chrome/browser/extensions/api/web_view/web_view_internal_api.cc
+++ b/extensions/browser/api/web_view/web_view_internal_api.cc
@@ -2,51 +2,23 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/extensions/api/web_view/web_view_internal_api.h"
+#include "extensions/browser/api/web_view/web_view_internal_api.h"
#include "base/strings/utf_string_conversions.h"
-#include "chrome/browser/extensions/api/browsing_data/browsing_data_api.h"
-#include "chrome/browser/extensions/api/context_menus/context_menus_api.h"
-#include "chrome/browser/extensions/api/context_menus/context_menus_api_helpers.h"
-#include "chrome/browser/extensions/tab_helper.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/common/extensions/api/web_view_internal.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
-#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/stop_find_action.h"
-#include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
-#include "extensions/common/error_utils.h"
+#include "extensions/common/api/web_view_internal.h"
#include "third_party/WebKit/public/web/WebFindOptions.h"
using content::WebContents;
-using extensions::api::web_view_internal::SetPermission::Params;
+using extensions::core_api::web_view_internal::SetPermission::Params;
using extensions::core_api::extension_types::InjectDetails;
-namespace helpers = extensions::context_menus_api_helpers;
-namespace webview = extensions::api::web_view_internal;
+namespace webview = extensions::core_api::web_view_internal;
namespace extensions {
-namespace {
-int MaskForKey(const char* key) {
- if (strcmp(key, extension_browsing_data_api_constants::kAppCacheKey) == 0)
- return content::StoragePartition::REMOVE_DATA_MASK_APPCACHE;
- if (strcmp(key, extension_browsing_data_api_constants::kCookiesKey) == 0)
- return content::StoragePartition::REMOVE_DATA_MASK_COOKIES;
- if (strcmp(key, extension_browsing_data_api_constants::kFileSystemsKey) == 0)
- return content::StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS;
- if (strcmp(key, extension_browsing_data_api_constants::kIndexedDBKey) == 0)
- return content::StoragePartition::REMOVE_DATA_MASK_INDEXEDDB;
- if (strcmp(key, extension_browsing_data_api_constants::kLocalStorageKey) == 0)
- return content::StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE;
- if (strcmp(key, extension_browsing_data_api_constants::kWebSQLKey) == 0)
- return content::StoragePartition::REMOVE_DATA_MASK_WEBSQL;
- return 0;
-}
-
-} // namespace
-
bool WebViewInternalExtensionFunction::RunAsync() {
int instance_id = 0;
EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &instance_id));
@@ -58,38 +30,6 @@ bool WebViewInternalExtensionFunction::RunAsync() {
return RunAsyncSafe(guest);
}
-// TODO(lazyboy): Add checks similar to
-// WebViewInternalExtensionFunction::RunAsyncSafe(WebViewGuest*).
-bool WebViewInternalContextMenusCreateFunction::RunAsync() {
- scoped_ptr<webview::ContextMenusCreate::Params> params(
- webview::ContextMenusCreate::Params::Create(*args_));
- EXTENSION_FUNCTION_VALIDATE(params.get());
-
- MenuItem::Id id(
- Profile::FromBrowserContext(browser_context())->IsOffTheRecord(),
- MenuItem::ExtensionKey(extension_id(), params->instance_id));
-
- if (params->create_properties.id.get()) {
- id.string_uid = *params->create_properties.id;
- } else {
- // The Generated Id is added by web_view_internal_custom_bindings.js.
- base::DictionaryValue* properties = NULL;
- EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &properties));
- EXTENSION_FUNCTION_VALIDATE(
- properties->GetInteger(helpers::kGeneratedIdKey, &id.uid));
- }
-
- bool success = extensions::context_menus_api_helpers::CreateMenuItem(
- params->create_properties,
- Profile::FromBrowserContext(browser_context()),
- extension(),
- id,
- &error_);
-
- SendResponse(success);
- return success;
-}
-
bool WebViewInternalNavigateFunction::RunAsyncSafe(WebViewGuest* guest) {
scoped_ptr<webview::Navigate::Params> params(
webview::Navigate::Params::Create(*args_));
@@ -99,163 +39,6 @@ bool WebViewInternalNavigateFunction::RunAsyncSafe(WebViewGuest* guest) {
return true;
}
-bool WebViewInternalContextMenusUpdateFunction::RunAsync() {
- scoped_ptr<webview::ContextMenusUpdate::Params> params(
- webview::ContextMenusUpdate::Params::Create(*args_));
- EXTENSION_FUNCTION_VALIDATE(params.get());
-
- Profile* profile = Profile::FromBrowserContext(browser_context());
- MenuItem::Id item_id(
- profile->IsOffTheRecord(),
- MenuItem::ExtensionKey(extension_id(), params->instance_id));
-
- if (params->id.as_string)
- item_id.string_uid = *params->id.as_string;
- else if (params->id.as_integer)
- item_id.uid = *params->id.as_integer;
- else
- NOTREACHED();
-
- bool success = extensions::context_menus_api_helpers::UpdateMenuItem(
- params->update_properties, profile, extension(), item_id, &error_);
- SendResponse(success);
- return success;
-}
-
-bool WebViewInternalContextMenusRemoveFunction::RunAsync() {
- scoped_ptr<webview::ContextMenusRemove::Params> params(
- webview::ContextMenusRemove::Params::Create(*args_));
- EXTENSION_FUNCTION_VALIDATE(params.get());
-
- MenuManager* menu_manager =
- MenuManager::Get(Profile::FromBrowserContext(browser_context()));
-
- MenuItem::Id id(
- Profile::FromBrowserContext(browser_context())->IsOffTheRecord(),
- MenuItem::ExtensionKey(extension_id(), params->instance_id));
-
- if (params->menu_item_id.as_string) {
- id.string_uid = *params->menu_item_id.as_string;
- } else if (params->menu_item_id.as_integer) {
- id.uid = *params->menu_item_id.as_integer;
- } else {
- NOTREACHED();
- }
-
- bool success = true;
- MenuItem* item = menu_manager->GetItemById(id);
- // Ensure one <webview> can't remove another's menu items.
- if (!item || item->id().extension_key != id.extension_key) {
- error_ = ErrorUtils::FormatErrorMessage(
- context_menus_api_helpers::kCannotFindItemError,
- context_menus_api_helpers::GetIDString(id));
- success = false;
- } else if (!menu_manager->RemoveContextMenuItem(id)) {
- success = false;
- }
-
- SendResponse(success);
- return success;
-}
-
-bool WebViewInternalContextMenusRemoveAllFunction::RunAsync() {
- scoped_ptr<webview::ContextMenusRemoveAll::Params> params(
- webview::ContextMenusRemoveAll::Params::Create(*args_));
- EXTENSION_FUNCTION_VALIDATE(params.get());
-
- MenuManager* menu_manager =
- MenuManager::Get(Profile::FromBrowserContext(browser_context()));
-
- int webview_instance_id = params->instance_id;
- menu_manager->RemoveAllContextItems(
- MenuItem::ExtensionKey(extension()->id(), webview_instance_id));
- SendResponse(true);
- return true;
-}
-
-WebViewInternalClearDataFunction::WebViewInternalClearDataFunction()
- : remove_mask_(0), bad_message_(false) {
-}
-
-WebViewInternalClearDataFunction::~WebViewInternalClearDataFunction() {
-}
-
-// Parses the |dataToRemove| argument to generate the remove mask. Sets
-// |bad_message_| (like EXTENSION_FUNCTION_VALIDATE would if this were a bool
-// method) if 'dataToRemove' is not present.
-uint32 WebViewInternalClearDataFunction::GetRemovalMask() {
- base::DictionaryValue* data_to_remove;
- if (!args_->GetDictionary(2, &data_to_remove)) {
- bad_message_ = true;
- return 0;
- }
-
- uint32 remove_mask = 0;
- for (base::DictionaryValue::Iterator i(*data_to_remove); !i.IsAtEnd();
- i.Advance()) {
- bool selected = false;
- if (!i.value().GetAsBoolean(&selected)) {
- bad_message_ = true;
- return 0;
- }
- if (selected)
- remove_mask |= MaskForKey(i.key().c_str());
- }
-
- return remove_mask;
-}
-
-// TODO(lazyboy): Parameters in this extension function are similar (or a
-// sub-set) to BrowsingDataRemoverFunction. How can we share this code?
-bool WebViewInternalClearDataFunction::RunAsyncSafe(WebViewGuest* guest) {
- // Grab the initial |options| parameter, and parse out the arguments.
- base::DictionaryValue* options;
- EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &options));
- DCHECK(options);
-
- // If |ms_since_epoch| isn't set, default it to 0.
- double ms_since_epoch;
- if (!options->GetDouble(extension_browsing_data_api_constants::kSinceKey,
- &ms_since_epoch)) {
- ms_since_epoch = 0;
- }
-
- // base::Time takes a double that represents seconds since epoch. JavaScript
- // gives developers milliseconds, so do a quick conversion before populating
- // the object. Also, Time::FromDoubleT converts double time 0 to empty Time
- // object. So we need to do special handling here.
- remove_since_ = (ms_since_epoch == 0)
- ? base::Time::UnixEpoch()
- : base::Time::FromDoubleT(ms_since_epoch / 1000.0);
-
- remove_mask_ = GetRemovalMask();
- if (bad_message_)
- return false;
-
- AddRef(); // Balanced below or in WebViewInternalClearDataFunction::Done().
-
- bool scheduled = false;
- if (remove_mask_) {
- scheduled = guest->ClearData(
- remove_since_,
- remove_mask_,
- base::Bind(&WebViewInternalClearDataFunction::ClearDataDone, this));
- }
- if (!remove_mask_ || !scheduled) {
- SendResponse(false);
- Release(); // Balanced above.
- return false;
- }
-
- // Will finish asynchronously.
- return true;
-}
-
-void WebViewInternalClearDataFunction::ClearDataDone() {
- Release(); // Balanced in RunAsync().
- SendResponse(true);
-}
-
WebViewInternalExecuteCodeFunction::WebViewInternalExecuteCodeFunction()
: guest_instance_id_(0), guest_src_(GURL::EmptyGURL()) {
}
@@ -532,8 +315,8 @@ bool WebViewInternalSetPermissionFunction::RunAsyncSafe(WebViewGuest* guest) {
web_view_permission_helper->SetPermission(
params->request_id, action, user_input);
- EXTENSION_FUNCTION_VALIDATE(
- result != WebViewPermissionHelper::SET_PERMISSION_INVALID);
+ EXTENSION_FUNCTION_VALIDATE(result !=
+ WebViewPermissionHelper::SET_PERMISSION_INVALID);
SetResult(new base::FundamentalValue(
result == WebViewPermissionHelper::SET_PERMISSION_ALLOWED));
@@ -541,27 +324,6 @@ bool WebViewInternalSetPermissionFunction::RunAsyncSafe(WebViewGuest* guest) {
return true;
}
-WebViewInternalShowContextMenuFunction::
- WebViewInternalShowContextMenuFunction() {
-}
-
-WebViewInternalShowContextMenuFunction::
- ~WebViewInternalShowContextMenuFunction() {
-}
-
-bool WebViewInternalShowContextMenuFunction::RunAsyncSafe(WebViewGuest* guest) {
- scoped_ptr<webview::ShowContextMenu::Params> params(
- webview::ShowContextMenu::Params::Create(*args_));
- EXTENSION_FUNCTION_VALIDATE(params.get());
-
- // TODO(lazyboy): Actually implement filtering menu items, we pass NULL for
- // now.
- guest->ShowContextMenu(params->request_id, NULL);
-
- SendResponse(true);
- return true;
-}
-
WebViewInternalOverrideUserAgentFunction::
WebViewInternalOverrideUserAgentFunction() {
}
« no previous file with comments | « extensions/browser/api/web_view/web_view_internal_api.h ('k') | extensions/browser/guest_view/web_view/web_view_constants.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698