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