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

Side by Side Diff: chrome/browser/extensions/api/omnibox/omnibox_api.cc

Issue 11440004: Remove deprecated extension EventRouter APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years 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 (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/omnibox/omnibox_api.h" 5 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 27 matching lines...) Expand all
38 const char kSuggestionDescriptionStylesRaw[] = "descriptionStylesRaw"; 38 const char kSuggestionDescriptionStylesRaw[] = "descriptionStylesRaw";
39 const char kDescriptionStylesType[] = "type"; 39 const char kDescriptionStylesType[] = "type";
40 const char kDescriptionStylesOffset[] = "offset"; 40 const char kDescriptionStylesOffset[] = "offset";
41 const char kDescriptionStylesLength[] = "length"; 41 const char kDescriptionStylesLength[] = "length";
42 42
43 } // namespace 43 } // namespace
44 44
45 // static 45 // static
46 void ExtensionOmniboxEventRouter::OnInputStarted( 46 void ExtensionOmniboxEventRouter::OnInputStarted(
47 Profile* profile, const std::string& extension_id) { 47 Profile* profile, const std::string& extension_id) {
48 scoped_ptr<ListValue> event_args(new ListValue()); 48 scoped_ptr<ListValue> args(new ListValue());
49 extensions::ExtensionSystem::Get(profile)->event_router()-> 49 scoped_ptr<Event> event(new Event(
50 DispatchEventToExtension(extension_id, events::kOnInputStarted, 50 events::kOnInputStarted, args.Pass()));
Yoyo Zhou 2012/12/05 22:28:32 I think you can inline the args (and make_scoped_p
Matt Perry 2012/12/05 22:53:53 Done.
51 event_args.Pass(), profile, GURL()); 51 event->restrict_to_profile = profile;
52 ExtensionSystem::Get(profile)->event_router()->
53 DispatchEventToExtension(extension_id, event.Pass());
52 } 54 }
53 55
54 // static 56 // static
55 bool ExtensionOmniboxEventRouter::OnInputChanged( 57 bool ExtensionOmniboxEventRouter::OnInputChanged(
56 Profile* profile, const std::string& extension_id, 58 Profile* profile, const std::string& extension_id,
57 const std::string& input, int suggest_id) { 59 const std::string& input, int suggest_id) {
58 if (!extensions::ExtensionSystem::Get(profile)->event_router()-> 60 if (!extensions::ExtensionSystem::Get(profile)->event_router()->
59 ExtensionHasEventListener(extension_id, events::kOnInputChanged)) 61 ExtensionHasEventListener(extension_id, events::kOnInputChanged))
60 return false; 62 return false;
61 63
62 scoped_ptr<ListValue> args(new ListValue()); 64 scoped_ptr<ListValue> args(new ListValue());
63 args->Set(0, Value::CreateStringValue(input)); 65 args->Set(0, Value::CreateStringValue(input));
64 args->Set(1, Value::CreateIntegerValue(suggest_id)); 66 args->Set(1, Value::CreateIntegerValue(suggest_id));
65 67
66 extensions::ExtensionSystem::Get(profile)->event_router()-> 68 scoped_ptr<Event> event(new Event(events::kOnInputChanged, args.Pass()));
67 DispatchEventToExtension(extension_id, events::kOnInputChanged, 69 event->restrict_to_profile = profile;
68 args.Pass(), profile, GURL()); 70 ExtensionSystem::Get(profile)->event_router()->
71 DispatchEventToExtension(extension_id, event.Pass());
69 return true; 72 return true;
70 } 73 }
71 74
72 // static 75 // static
73 void ExtensionOmniboxEventRouter::OnInputEntered( 76 void ExtensionOmniboxEventRouter::OnInputEntered(
74 content::WebContents* web_contents, 77 content::WebContents* web_contents,
75 const std::string& extension_id, 78 const std::string& extension_id,
76 const std::string& input) { 79 const std::string& input) {
77 Profile* profile = 80 Profile* profile =
78 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 81 Profile::FromBrowserContext(web_contents->GetBrowserContext());
79 82
80 const Extension* extension = 83 const Extension* extension =
81 ExtensionSystem::Get(profile)->extension_service()->extensions()-> 84 ExtensionSystem::Get(profile)->extension_service()->extensions()->
82 GetByID(extension_id); 85 GetByID(extension_id);
83 CHECK(extension); 86 CHECK(extension);
84 extensions::TabHelper::FromWebContents(web_contents)-> 87 extensions::TabHelper::FromWebContents(web_contents)->
85 active_tab_permission_granter()->GrantIfRequested(extension); 88 active_tab_permission_granter()->GrantIfRequested(extension);
86 89
87 scoped_ptr<ListValue> args(new ListValue()); 90 scoped_ptr<ListValue> args(new ListValue());
88 args->Set(0, Value::CreateStringValue(input)); 91 args->Set(0, Value::CreateStringValue(input));
89 92
90 extensions::ExtensionSystem::Get(profile)->event_router()-> 93 scoped_ptr<Event> event(new Event(events::kOnInputEntered, args.Pass()));
91 DispatchEventToExtension(extension_id, events::kOnInputEntered, 94 event->restrict_to_profile = profile;
92 args.Pass(), profile, GURL()); 95 ExtensionSystem::Get(profile)->event_router()->
96 DispatchEventToExtension(extension_id, event.Pass());
93 97
94 content::NotificationService::current()->Notify( 98 content::NotificationService::current()->Notify(
95 chrome::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED, 99 chrome::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED,
96 content::Source<Profile>(profile), 100 content::Source<Profile>(profile),
97 content::NotificationService::NoDetails()); 101 content::NotificationService::NoDetails());
98 } 102 }
99 103
100 // static 104 // static
101 void ExtensionOmniboxEventRouter::OnInputCancelled( 105 void ExtensionOmniboxEventRouter::OnInputCancelled(
102 Profile* profile, const std::string& extension_id) { 106 Profile* profile, const std::string& extension_id) {
103 scoped_ptr<ListValue> args(new ListValue()); 107 scoped_ptr<ListValue> args(new ListValue());
104 extensions::ExtensionSystem::Get(profile)->event_router()-> 108 scoped_ptr<Event> event(new Event(events::kOnInputCancelled, args.Pass()));
105 DispatchEventToExtension(extension_id, events::kOnInputCancelled, 109 event->restrict_to_profile = profile;
106 args.Pass(), profile, GURL()); 110 ExtensionSystem::Get(profile)->event_router()->
111 DispatchEventToExtension(extension_id, event.Pass());
107 } 112 }
108 113
109 bool OmniboxSendSuggestionsFunction::RunImpl() { 114 bool OmniboxSendSuggestionsFunction::RunImpl() {
110 ExtensionOmniboxSuggestions suggestions; 115 ExtensionOmniboxSuggestions suggestions;
111 ListValue* suggestions_value; 116 ListValue* suggestions_value;
112 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &suggestions.request_id)); 117 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &suggestions.request_id));
113 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &suggestions_value)); 118 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &suggestions_value));
114 119
115 suggestions.suggestions.resize(suggestions_value->GetSize()); 120 suggestions.suggestions.resize(suggestions_value->GetSize());
116 for (size_t i = 0; i < suggestions_value->GetSize(); ++i) { 121 for (size_t i = 0; i < suggestions_value->GetSize(); ++i) {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 for (size_t i = 0; i < description_styles.size(); ++i) { 305 for (size_t i = 0; i < description_styles.size(); ++i) {
301 if (description_styles[i].offset > placeholder) 306 if (description_styles[i].offset > placeholder)
302 description_styles[i].offset += replacement.length() - 2; 307 description_styles[i].offset += replacement.length() - 2;
303 } 308 }
304 } 309 }
305 310
306 match->contents.assign(description); 311 match->contents.assign(description);
307 } 312 }
308 313
309 } // namespace extensions 314 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698