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

Side by Side Diff: extensions/browser/api/declarative/declarative_api.cc

Issue 550403003: Move declarative api files to extensions/browser/api/declarative. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix browser tests. 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/declarative/declarative_api.h" 5 #include "extensions/browser/api/declarative/declarative_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/task_runner_util.h" 9 #include "base/task_runner_util.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h"
12 #include "chrome/common/extensions/api/events.h"
13 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/render_process_host.h" 12 #include "content/public/browser/render_process_host.h"
15 #include "content/public/browser/render_view_host.h" 13 #include "content/public/browser/render_view_host.h"
14 #include "content/public/browser/web_contents.h"
15 #include "extensions/browser/api/extensions_api_client.h"
16 #include "extensions/browser/extension_system.h" 16 #include "extensions/browser/extension_system.h"
17 #include "extensions/browser/guest_view/web_view/web_view_constants.h" 17 #include "extensions/browser/guest_view/web_view/web_view_constants.h"
18 #include "extensions/browser/guest_view/web_view/web_view_guest.h" 18 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
19 #include "extensions/common/api/events.h"
19 #include "extensions/common/extension_api.h" 20 #include "extensions/common/extension_api.h"
20 #include "extensions/common/permissions/permissions_data.h" 21 #include "extensions/common/permissions/permissions_data.h"
21 22
22 using extensions::api::events::Rule; 23 using extensions::core_api::events::Rule;
23 24
24 namespace AddRules = extensions::api::events::Event::AddRules; 25 namespace AddRules = extensions::core_api::events::Event::AddRules;
25 namespace GetRules = extensions::api::events::Event::GetRules; 26 namespace GetRules = extensions::core_api::events::Event::GetRules;
26 namespace RemoveRules = extensions::api::events::Event::RemoveRules; 27 namespace RemoveRules = extensions::core_api::events::Event::RemoveRules;
27 28
28 29
29 namespace extensions { 30 namespace extensions {
30 31
31 namespace { 32 namespace {
32 33
33 const char kWebRequest[] = "declarativeWebRequest."; 34 const char kWebRequest[] = "declarativeWebRequest.";
34 const char kWebViewExpectedError[] = "Webview event with Webview ID expected."; 35 const char kWebViewExpectedError[] = "Webview event with Webview ID expected.";
35 36
36 bool IsWebViewEvent(const std::string& event_name) { 37 bool IsWebViewEvent(const std::string& event_name) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 int webview_instance_id = 0; 83 int webview_instance_id = 0;
83 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &webview_instance_id)); 84 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &webview_instance_id));
84 int embedder_process_id = render_view_host()->GetProcess()->GetID(); 85 int embedder_process_id = render_view_host()->GetProcess()->GetID();
85 86
86 bool has_webview = webview_instance_id != 0; 87 bool has_webview = webview_instance_id != 0;
87 if (has_webview != IsWebViewEvent(event_name)) 88 if (has_webview != IsWebViewEvent(event_name))
88 EXTENSION_FUNCTION_ERROR(kWebViewExpectedError); 89 EXTENSION_FUNCTION_ERROR(kWebViewExpectedError);
89 event_name = GetWebRequestEventName(event_name); 90 event_name = GetWebRequestEventName(event_name);
90 91
91 // If we are not operating on a particular <webview>, then the key is (0, 0). 92 // If we are not operating on a particular <webview>, then the key is (0, 0).
92 RulesRegistryService::WebViewKey key( 93 RulesRegistry::WebViewKey key(
93 webview_instance_id ? embedder_process_id : 0, webview_instance_id); 94 webview_instance_id ? embedder_process_id : 0, webview_instance_id);
94 95
95 RulesRegistryService* rules_registry_service = 96 // The following call will return a NULL pointer for apps_shell, but should
96 RulesRegistryService::Get(browser_context()); 97 // never be called there anyways.
97 rules_registry_ = rules_registry_service->GetRulesRegistry(key, event_name); 98 rules_registry_ = ExtensionsAPIClient::Get()->GetRulesRegistry(
99 browser_context(), key, event_name);
100 DCHECK(rules_registry_.get());
98 // Raw access to this function is not available to extensions, therefore 101 // Raw access to this function is not available to extensions, therefore
99 // there should never be a request for a nonexisting rules registry. 102 // there should never be a request for a nonexisting rules registry.
100 EXTENSION_FUNCTION_VALIDATE(rules_registry_.get()); 103 EXTENSION_FUNCTION_VALIDATE(rules_registry_.get());
101 104
102 if (content::BrowserThread::CurrentlyOn(rules_registry_->owner_thread())) { 105 if (content::BrowserThread::CurrentlyOn(rules_registry_->owner_thread())) {
103 bool success = RunAsyncOnCorrectThread(); 106 bool success = RunAsyncOnCorrectThread();
104 SendResponse(success); 107 SendResponse(success);
105 } else { 108 } else {
106 scoped_refptr<base::MessageLoopProxy> message_loop_proxy = 109 scoped_refptr<base::MessageLoopProxy> message_loop_proxy =
107 content::BrowserThread::GetMessageLoopProxyForThread( 110 content::BrowserThread::GetMessageLoopProxyForThread(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } else { 156 } else {
154 rules_registry_->GetAllRules(extension_id(), &rules); 157 rules_registry_->GetAllRules(extension_id(), &rules);
155 } 158 }
156 159
157 results_ = GetRules::Results::Create(rules); 160 results_ = GetRules::Results::Create(rules);
158 161
159 return true; 162 return true;
160 } 163 }
161 164
162 } // namespace extensions 165 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/declarative/declarative_api.h ('k') | extensions/browser/api/declarative/declarative_rule.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698