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 "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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 const char kDescriptionStylesType[] = "type"; | 45 const char kDescriptionStylesType[] = "type"; |
46 const char kDescriptionStylesOffset[] = "offset"; | 46 const char kDescriptionStylesOffset[] = "offset"; |
47 const char kDescriptionStylesLength[] = "length"; | 47 const char kDescriptionStylesLength[] = "length"; |
48 | 48 |
49 } // namespace | 49 } // namespace |
50 | 50 |
51 // static | 51 // static |
52 void ExtensionOmniboxEventRouter::OnInputStarted( | 52 void ExtensionOmniboxEventRouter::OnInputStarted( |
53 Profile* profile, const std::string& extension_id) { | 53 Profile* profile, const std::string& extension_id) { |
54 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 54 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
55 extension_id, events::kOnInputStarted, "[]", profile, GURL()); | 55 extension_id, events::kOnInputStarted, NULL, profile, GURL()); |
56 } | 56 } |
57 | 57 |
58 // static | 58 // static |
59 bool ExtensionOmniboxEventRouter::OnInputChanged( | 59 bool ExtensionOmniboxEventRouter::OnInputChanged( |
60 Profile* profile, const std::string& extension_id, | 60 Profile* profile, const std::string& extension_id, |
61 const std::string& input, int suggest_id) { | 61 const std::string& input, int suggest_id) { |
62 if (!profile->GetExtensionEventRouter()->ExtensionHasEventListener( | 62 if (!profile->GetExtensionEventRouter()->ExtensionHasEventListener( |
63 extension_id, events::kOnInputChanged)) | 63 extension_id, events::kOnInputChanged)) |
64 return false; | 64 return false; |
65 | 65 |
66 ListValue args; | 66 ListValue* args = new ListValue(); |
67 args.Set(0, Value::CreateStringValue(input)); | 67 args->Set(0, Value::CreateStringValue(input)); |
68 args.Set(1, Value::CreateIntegerValue(suggest_id)); | 68 args->Set(1, Value::CreateIntegerValue(suggest_id)); |
69 std::string json_args; | |
70 base::JSONWriter::Write(&args, &json_args); | |
71 | 69 |
72 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 70 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
73 extension_id, events::kOnInputChanged, json_args, profile, GURL()); | 71 extension_id, events::kOnInputChanged, args, profile, GURL()); |
74 return true; | 72 return true; |
75 } | 73 } |
76 | 74 |
77 // static | 75 // static |
78 void ExtensionOmniboxEventRouter::OnInputEntered( | 76 void ExtensionOmniboxEventRouter::OnInputEntered( |
79 TabContents* tab_contents, | 77 TabContents* tab_contents, |
80 const std::string& extension_id, | 78 const std::string& extension_id, |
81 const std::string& input) { | 79 const std::string& input) { |
82 ListValue args; | 80 ListValue* args = new ListValue(); |
83 args.Set(0, Value::CreateStringValue(input)); | 81 args->Set(0, Value::CreateStringValue(input)); |
84 std::string json_args; | |
85 base::JSONWriter::Write(&args, &json_args); | |
86 | 82 |
87 tab_contents->extension_tab_helper()->active_tab_permission_manager()-> | 83 tab_contents->extension_tab_helper()->active_tab_permission_manager()-> |
88 GrantIfRequested(extension_id); | 84 GrantIfRequested(extension_id); |
89 | 85 |
90 Profile* profile = tab_contents->profile(); | 86 Profile* profile = tab_contents->profile(); |
91 | 87 |
92 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 88 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
93 extension_id, events::kOnInputEntered, json_args, profile, GURL()); | 89 extension_id, events::kOnInputEntered, args, profile, GURL()); |
94 | 90 |
95 content::NotificationService::current()->Notify( | 91 content::NotificationService::current()->Notify( |
96 chrome::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED, | 92 chrome::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED, |
97 content::Source<Profile>(profile), | 93 content::Source<Profile>(profile), |
98 content::NotificationService::NoDetails()); | 94 content::NotificationService::NoDetails()); |
99 } | 95 } |
100 | 96 |
101 // static | 97 // static |
102 void ExtensionOmniboxEventRouter::OnInputCancelled( | 98 void ExtensionOmniboxEventRouter::OnInputCancelled( |
103 Profile* profile, const std::string& extension_id) { | 99 Profile* profile, const std::string& extension_id) { |
104 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 100 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
105 extension_id, events::kOnInputCancelled, "[]", profile, GURL()); | 101 extension_id, events::kOnInputCancelled, NULL, profile, GURL()); |
106 } | 102 } |
107 | 103 |
108 bool OmniboxSendSuggestionsFunction::RunImpl() { | 104 bool OmniboxSendSuggestionsFunction::RunImpl() { |
109 ExtensionOmniboxSuggestions suggestions; | 105 ExtensionOmniboxSuggestions suggestions; |
110 ListValue* suggestions_value; | 106 ListValue* suggestions_value; |
111 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &suggestions.request_id)); | 107 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &suggestions.request_id)); |
112 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &suggestions_value)); | 108 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &suggestions_value)); |
113 | 109 |
114 suggestions.suggestions.resize(suggestions_value->GetSize()); | 110 suggestions.suggestions.resize(suggestions_value->GetSize()); |
115 for (size_t i = 0; i < suggestions_value->GetSize(); ++i) { | 111 for (size_t i = 0; i < suggestions_value->GetSize(); ++i) { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 for (size_t i = 0; i < description_styles.size(); ++i) { | 295 for (size_t i = 0; i < description_styles.size(); ++i) { |
300 if (description_styles[i].offset > placeholder) | 296 if (description_styles[i].offset > placeholder) |
301 description_styles[i].offset += replacement.length() - 2; | 297 description_styles[i].offset += replacement.length() - 2; |
302 } | 298 } |
303 } | 299 } |
304 | 300 |
305 match->contents.assign(description); | 301 match->contents.assign(description); |
306 } | 302 } |
307 | 303 |
308 } // namespace extensions | 304 } // namespace extensions |
OLD | NEW |