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 |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
jdoerrie
2017/04/06 14:25:50
#include "base/values.h"
vabr (Chromium)
2017/04/07 20:40:40
Done.
| |
15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
16 #include "chrome/browser/extensions/tab_helper.h" | 16 #include "chrome/browser/extensions/tab_helper.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/search_engines/template_url_service_factory.h" | 18 #include "chrome/browser/search_engines/template_url_service_factory.h" |
19 #include "chrome/common/extensions/api/omnibox.h" | 19 #include "chrome/common/extensions/api/omnibox.h" |
20 #include "chrome/common/extensions/api/omnibox/omnibox_handler.h" | 20 #include "chrome/common/extensions/api/omnibox/omnibox_handler.h" |
21 #include "components/search_engines/template_url.h" | 21 #include "components/search_engines/template_url.h" |
22 #include "components/search_engines/template_url_service.h" | 22 #include "components/search_engines/template_url_service.h" |
23 #include "content/public/browser/notification_details.h" | 23 #include "content/public/browser/notification_details.h" |
24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
(...skipping 42 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::Value("")); | 77 dict->SetWithoutPathExpansion( |
78 kSuggestionContent, | |
79 base::MakeUnique<base::Value>(base::Value::Type::STRING)); | |
78 prefs->UpdateExtensionPref(extension_id, kOmniboxDefaultSuggestion, | 80 prefs->UpdateExtensionPref(extension_id, kOmniboxDefaultSuggestion, |
79 std::move(dict)); | 81 std::move(dict)); |
80 | 82 |
81 return true; | 83 return true; |
82 } | 84 } |
83 | 85 |
84 // Returns a string used as a template URL string of the extension. | 86 // Returns a string used as a template URL string of the extension. |
85 std::string GetTemplateURLStringForExtension(const std::string& extension_id) { | 87 std::string GetTemplateURLStringForExtension(const std::string& extension_id) { |
86 // This URL is not actually used for navigation. It holds the extension's ID. | 88 // This URL is not actually used for navigation. It holds the extension's ID. |
87 return std::string(extensions::kExtensionScheme) + "://" + | 89 return std::string(extensions::kExtensionScheme) + "://" + |
(...skipping 16 matching lines...) Expand all Loading... | |
104 // static | 106 // static |
105 bool ExtensionOmniboxEventRouter::OnInputChanged( | 107 bool ExtensionOmniboxEventRouter::OnInputChanged( |
106 Profile* profile, const std::string& extension_id, | 108 Profile* profile, const std::string& extension_id, |
107 const std::string& input, int suggest_id) { | 109 const std::string& input, int suggest_id) { |
108 EventRouter* event_router = EventRouter::Get(profile); | 110 EventRouter* event_router = EventRouter::Get(profile); |
109 if (!event_router->ExtensionHasEventListener( | 111 if (!event_router->ExtensionHasEventListener( |
110 extension_id, omnibox::OnInputChanged::kEventName)) | 112 extension_id, omnibox::OnInputChanged::kEventName)) |
111 return false; | 113 return false; |
112 | 114 |
113 std::unique_ptr<base::ListValue> args(new base::ListValue()); | 115 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
114 args->Set(0, new base::Value(input)); | 116 args->Set(0, base::MakeUnique<base::Value>(input)); |
115 args->Set(1, new base::Value(suggest_id)); | 117 args->Set(1, base::MakeUnique<base::Value>(suggest_id)); |
116 | 118 |
117 std::unique_ptr<Event> event = base::MakeUnique<Event>( | 119 std::unique_ptr<Event> event = base::MakeUnique<Event>( |
118 events::OMNIBOX_ON_INPUT_CHANGED, omnibox::OnInputChanged::kEventName, | 120 events::OMNIBOX_ON_INPUT_CHANGED, omnibox::OnInputChanged::kEventName, |
119 std::move(args)); | 121 std::move(args)); |
120 event->restrict_to_browser_context = profile; | 122 event->restrict_to_browser_context = profile; |
121 event_router->DispatchEventToExtension(extension_id, std::move(event)); | 123 event_router->DispatchEventToExtension(extension_id, std::move(event)); |
122 return true; | 124 return true; |
123 } | 125 } |
124 | 126 |
125 // static | 127 // static |
126 void ExtensionOmniboxEventRouter::OnInputEntered( | 128 void ExtensionOmniboxEventRouter::OnInputEntered( |
127 content::WebContents* web_contents, | 129 content::WebContents* web_contents, |
128 const std::string& extension_id, | 130 const std::string& extension_id, |
129 const std::string& input, | 131 const std::string& input, |
130 WindowOpenDisposition disposition) { | 132 WindowOpenDisposition disposition) { |
131 Profile* profile = | 133 Profile* profile = |
132 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 134 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
133 | 135 |
134 const Extension* extension = | 136 const Extension* extension = |
135 ExtensionRegistry::Get(profile)->enabled_extensions().GetByID( | 137 ExtensionRegistry::Get(profile)->enabled_extensions().GetByID( |
136 extension_id); | 138 extension_id); |
137 CHECK(extension); | 139 CHECK(extension); |
138 extensions::TabHelper::FromWebContents(web_contents)-> | 140 extensions::TabHelper::FromWebContents(web_contents)-> |
139 active_tab_permission_granter()->GrantIfRequested(extension); | 141 active_tab_permission_granter()->GrantIfRequested(extension); |
140 | 142 |
141 std::unique_ptr<base::ListValue> args(new base::ListValue()); | 143 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
142 args->Set(0, new base::Value(input)); | 144 args->Set(0, base::MakeUnique<base::Value>(input)); |
143 if (disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB) | 145 if (disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB) |
144 args->Set(1, new base::Value(kForegroundTabDisposition)); | 146 args->Set(1, base::MakeUnique<base::Value>(kForegroundTabDisposition)); |
145 else if (disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB) | 147 else if (disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB) |
146 args->Set(1, new base::Value(kBackgroundTabDisposition)); | 148 args->Set(1, base::MakeUnique<base::Value>(kBackgroundTabDisposition)); |
147 else | 149 else |
148 args->Set(1, new base::Value(kCurrentTabDisposition)); | 150 args->Set(1, base::MakeUnique<base::Value>(kCurrentTabDisposition)); |
149 | 151 |
150 std::unique_ptr<Event> event = base::MakeUnique<Event>( | 152 std::unique_ptr<Event> event = base::MakeUnique<Event>( |
151 events::OMNIBOX_ON_INPUT_ENTERED, omnibox::OnInputEntered::kEventName, | 153 events::OMNIBOX_ON_INPUT_ENTERED, omnibox::OnInputEntered::kEventName, |
152 std::move(args)); | 154 std::move(args)); |
153 event->restrict_to_browser_context = profile; | 155 event->restrict_to_browser_context = profile; |
154 EventRouter::Get(profile) | 156 EventRouter::Get(profile) |
155 ->DispatchEventToExtension(extension_id, std::move(event)); | 157 ->DispatchEventToExtension(extension_id, std::move(event)); |
156 | 158 |
157 content::NotificationService::current()->Notify( | 159 content::NotificationService::current()->Notify( |
158 extensions::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED, | 160 extensions::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED, |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
375 for (size_t i = 0; i < description_styles.size(); ++i) { | 377 for (size_t i = 0; i < description_styles.size(); ++i) { |
376 if (description_styles[i].offset > placeholder) | 378 if (description_styles[i].offset > placeholder) |
377 description_styles[i].offset += replacement.length() - 2; | 379 description_styles[i].offset += replacement.length() - 2; |
378 } | 380 } |
379 } | 381 } |
380 | 382 |
381 match->contents.assign(description); | 383 match->contents.assign(description); |
382 } | 384 } |
383 | 385 |
384 } // namespace extensions | 386 } // namespace extensions |
OLD | NEW |