OLD | NEW |
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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 Profile* profile, | 67 Profile* profile, |
68 const std::string& extension_id, | 68 const std::string& extension_id, |
69 const omnibox::DefaultSuggestResult& suggestion) { | 69 const omnibox::DefaultSuggestResult& suggestion) { |
70 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile); | 70 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile); |
71 if (!prefs) | 71 if (!prefs) |
72 return false; | 72 return false; |
73 | 73 |
74 std::unique_ptr<base::DictionaryValue> dict = suggestion.ToValue(); | 74 std::unique_ptr<base::DictionaryValue> dict = suggestion.ToValue(); |
75 // Add the content field so that the dictionary can be used to populate an | 75 // Add the content field so that the dictionary can be used to populate an |
76 // omnibox::SuggestResult. | 76 // omnibox::SuggestResult. |
77 dict->SetWithoutPathExpansion(kSuggestionContent, new base::StringValue("")); | 77 dict->SetWithoutPathExpansion(kSuggestionContent, new base::Value("")); |
78 prefs->UpdateExtensionPref(extension_id, | 78 prefs->UpdateExtensionPref(extension_id, |
79 kOmniboxDefaultSuggestion, | 79 kOmniboxDefaultSuggestion, |
80 dict.release()); | 80 dict.release()); |
81 | 81 |
82 return true; | 82 return true; |
83 } | 83 } |
84 | 84 |
85 // Returns a string used as a template URL string of the extension. | 85 // Returns a string used as a template URL string of the extension. |
86 std::string GetTemplateURLStringForExtension(const std::string& extension_id) { | 86 std::string GetTemplateURLStringForExtension(const std::string& extension_id) { |
87 // This URL is not actually used for navigation. It holds the extension's ID. | 87 // This URL is not actually used for navigation. It holds the extension's ID. |
(...skipping 17 matching lines...) Expand all Loading... |
105 // static | 105 // static |
106 bool ExtensionOmniboxEventRouter::OnInputChanged( | 106 bool ExtensionOmniboxEventRouter::OnInputChanged( |
107 Profile* profile, const std::string& extension_id, | 107 Profile* profile, const std::string& extension_id, |
108 const std::string& input, int suggest_id) { | 108 const std::string& input, int suggest_id) { |
109 EventRouter* event_router = EventRouter::Get(profile); | 109 EventRouter* event_router = EventRouter::Get(profile); |
110 if (!event_router->ExtensionHasEventListener( | 110 if (!event_router->ExtensionHasEventListener( |
111 extension_id, omnibox::OnInputChanged::kEventName)) | 111 extension_id, omnibox::OnInputChanged::kEventName)) |
112 return false; | 112 return false; |
113 | 113 |
114 std::unique_ptr<base::ListValue> args(new base::ListValue()); | 114 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
115 args->Set(0, new base::StringValue(input)); | 115 args->Set(0, new base::Value(input)); |
116 args->Set(1, new base::Value(suggest_id)); | 116 args->Set(1, new base::Value(suggest_id)); |
117 | 117 |
118 std::unique_ptr<Event> event = base::MakeUnique<Event>( | 118 std::unique_ptr<Event> event = base::MakeUnique<Event>( |
119 events::OMNIBOX_ON_INPUT_CHANGED, omnibox::OnInputChanged::kEventName, | 119 events::OMNIBOX_ON_INPUT_CHANGED, omnibox::OnInputChanged::kEventName, |
120 std::move(args)); | 120 std::move(args)); |
121 event->restrict_to_browser_context = profile; | 121 event->restrict_to_browser_context = profile; |
122 event_router->DispatchEventToExtension(extension_id, std::move(event)); | 122 event_router->DispatchEventToExtension(extension_id, std::move(event)); |
123 return true; | 123 return true; |
124 } | 124 } |
125 | 125 |
126 // static | 126 // static |
127 void ExtensionOmniboxEventRouter::OnInputEntered( | 127 void ExtensionOmniboxEventRouter::OnInputEntered( |
128 content::WebContents* web_contents, | 128 content::WebContents* web_contents, |
129 const std::string& extension_id, | 129 const std::string& extension_id, |
130 const std::string& input, | 130 const std::string& input, |
131 WindowOpenDisposition disposition) { | 131 WindowOpenDisposition disposition) { |
132 Profile* profile = | 132 Profile* profile = |
133 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 133 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
134 | 134 |
135 const Extension* extension = | 135 const Extension* extension = |
136 ExtensionRegistry::Get(profile)->enabled_extensions().GetByID( | 136 ExtensionRegistry::Get(profile)->enabled_extensions().GetByID( |
137 extension_id); | 137 extension_id); |
138 CHECK(extension); | 138 CHECK(extension); |
139 extensions::TabHelper::FromWebContents(web_contents)-> | 139 extensions::TabHelper::FromWebContents(web_contents)-> |
140 active_tab_permission_granter()->GrantIfRequested(extension); | 140 active_tab_permission_granter()->GrantIfRequested(extension); |
141 | 141 |
142 std::unique_ptr<base::ListValue> args(new base::ListValue()); | 142 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
143 args->Set(0, new base::StringValue(input)); | 143 args->Set(0, new base::Value(input)); |
144 if (disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB) | 144 if (disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB) |
145 args->Set(1, new base::StringValue(kForegroundTabDisposition)); | 145 args->Set(1, new base::Value(kForegroundTabDisposition)); |
146 else if (disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB) | 146 else if (disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB) |
147 args->Set(1, new base::StringValue(kBackgroundTabDisposition)); | 147 args->Set(1, new base::Value(kBackgroundTabDisposition)); |
148 else | 148 else |
149 args->Set(1, new base::StringValue(kCurrentTabDisposition)); | 149 args->Set(1, new base::Value(kCurrentTabDisposition)); |
150 | 150 |
151 std::unique_ptr<Event> event = base::MakeUnique<Event>( | 151 std::unique_ptr<Event> event = base::MakeUnique<Event>( |
152 events::OMNIBOX_ON_INPUT_ENTERED, omnibox::OnInputEntered::kEventName, | 152 events::OMNIBOX_ON_INPUT_ENTERED, omnibox::OnInputEntered::kEventName, |
153 std::move(args)); | 153 std::move(args)); |
154 event->restrict_to_browser_context = profile; | 154 event->restrict_to_browser_context = profile; |
155 EventRouter::Get(profile) | 155 EventRouter::Get(profile) |
156 ->DispatchEventToExtension(extension_id, std::move(event)); | 156 ->DispatchEventToExtension(extension_id, std::move(event)); |
157 | 157 |
158 content::NotificationService::current()->Notify( | 158 content::NotificationService::current()->Notify( |
159 extensions::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED, | 159 extensions::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED, |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 for (size_t i = 0; i < description_styles.size(); ++i) { | 375 for (size_t i = 0; i < description_styles.size(); ++i) { |
376 if (description_styles[i].offset > placeholder) | 376 if (description_styles[i].offset > placeholder) |
377 description_styles[i].offset += replacement.length() - 2; | 377 description_styles[i].offset += replacement.length() - 2; |
378 } | 378 } |
379 } | 379 } |
380 | 380 |
381 match->contents.assign(description); | 381 match->contents.assign(description); |
382 } | 382 } |
383 | 383 |
384 } // namespace extensions | 384 } // namespace extensions |
OLD | NEW |