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

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

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

Powered by Google App Engine
This is Rietveld 408576698