OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/renderer/searchbox/searchbox_extension.h" | 5 #include "chrome/renderer/searchbox/searchbox_extension.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
13 #include "base/json/string_escape.h" | 13 #include "base/json/string_escape.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
19 #include "chrome/common/search/instant_types.h" | 19 #include "chrome/common/search/instant_types.h" |
20 #include "chrome/common/search/ntp_logging_events.h" | 20 #include "chrome/common/search/ntp_logging_events.h" |
21 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
22 #include "chrome/grit/renderer_resources.h" | 22 #include "chrome/grit/renderer_resources.h" |
23 #include "chrome/renderer/searchbox/searchbox.h" | 23 #include "chrome/renderer/searchbox/searchbox.h" |
24 #include "components/crx_file/id_util.h" | 24 #include "components/crx_file/id_util.h" |
25 #include "components/ntp_tiles/tile_source.h" | 25 #include "components/ntp_tiles/tile_source.h" |
26 #include "components/ntp_tiles/tile_visual_type.h" | |
26 #include "content/public/renderer/render_frame.h" | 27 #include "content/public/renderer/render_frame.h" |
27 #include "content/public/renderer/render_view.h" | 28 #include "content/public/renderer/render_view.h" |
28 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 29 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
29 #include "third_party/WebKit/public/web/WebDocument.h" | 30 #include "third_party/WebKit/public/web/WebDocument.h" |
30 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 31 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
31 #include "third_party/WebKit/public/web/WebScriptSource.h" | 32 #include "third_party/WebKit/public/web/WebScriptSource.h" |
32 #include "third_party/WebKit/public/web/WebView.h" | 33 #include "third_party/WebKit/public/web/WebView.h" |
33 #include "ui/base/resource/resource_bundle.h" | 34 #include "ui/base/resource/resource_bundle.h" |
34 #include "ui/base/window_open_disposition.h" | 35 #include "ui/base/window_open_disposition.h" |
35 #include "ui/events/keycodes/keyboard_codes.h" | 36 #include "ui/events/keycodes/keyboard_codes.h" |
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
987 } | 988 } |
988 | 989 |
989 // static | 990 // static |
990 void SearchBoxExtensionWrapper::LogMostVisitedImpression( | 991 void SearchBoxExtensionWrapper::LogMostVisitedImpression( |
991 const v8::FunctionCallbackInfo<v8::Value>& args) { | 992 const v8::FunctionCallbackInfo<v8::Value>& args) { |
992 content::RenderFrame* render_frame = GetRenderFrameWithCheckedOrigin( | 993 content::RenderFrame* render_frame = GetRenderFrameWithCheckedOrigin( |
993 GURL(chrome::kChromeSearchMostVisitedUrl)); | 994 GURL(chrome::kChromeSearchMostVisitedUrl)); |
994 if (!render_frame) | 995 if (!render_frame) |
995 return; | 996 return; |
996 | 997 |
997 if (args.Length() < 2 || !args[0]->IsNumber() || !args[1]->IsNumber()) { | 998 if (args.Length() < 3 || !args[0]->IsNumber() || !args[1]->IsNumber() || |
999 !args[2]->IsNumber()) { | |
998 ThrowInvalidParameters(args); | 1000 ThrowInvalidParameters(args); |
999 return; | 1001 return; |
1000 } | 1002 } |
1001 | 1003 |
1002 DVLOG(1) << render_frame << " LogMostVisitedImpression"; | 1004 DVLOG(1) << render_frame << " LogMostVisitedImpression"; |
1003 | 1005 |
1004 if (args[1]->Uint32Value() <= static_cast<int>(ntp_tiles::TileSource::LAST)) { | 1006 if (args[1]->Uint32Value() <= static_cast<int>(ntp_tiles::TileSource::LAST) && |
1007 args[2]->Uint32Value() <= ntp_tiles::MAX_RECORDED_TILE_TYPE) { | |
sfiera
2017/04/06 08:53:28
Can we instead check here only that args[2] is a v
Marc Treib
2017/04/06 09:16:44
Done.
| |
1005 ntp_tiles::TileSource tile_source = | 1008 ntp_tiles::TileSource tile_source = |
1006 static_cast<ntp_tiles::TileSource>(args[1]->Uint32Value()); | 1009 static_cast<ntp_tiles::TileSource>(args[1]->Uint32Value()); |
1010 ntp_tiles::TileVisualType tile_type = | |
sfiera
2017/04/06 08:53:28
Optional: with the static_cast<>, seems like a goo
Marc Treib
2017/04/06 09:16:44
Done.
| |
1011 static_cast<ntp_tiles::TileVisualType>(args[2]->Uint32Value()); | |
1007 SearchBox::Get(render_frame) | 1012 SearchBox::Get(render_frame) |
1008 ->LogMostVisitedImpression(args[0]->IntegerValue(), tile_source); | 1013 ->LogMostVisitedImpression(args[0]->IntegerValue(), tile_source, |
1014 tile_type); | |
1009 } | 1015 } |
1010 } | 1016 } |
1011 | 1017 |
1012 // static | 1018 // static |
1013 void SearchBoxExtensionWrapper::LogMostVisitedNavigation( | 1019 void SearchBoxExtensionWrapper::LogMostVisitedNavigation( |
1014 const v8::FunctionCallbackInfo<v8::Value>& args) { | 1020 const v8::FunctionCallbackInfo<v8::Value>& args) { |
1015 content::RenderFrame* render_frame = GetRenderFrameWithCheckedOrigin( | 1021 content::RenderFrame* render_frame = GetRenderFrameWithCheckedOrigin( |
1016 GURL(chrome::kChromeSearchMostVisitedUrl)); | 1022 GURL(chrome::kChromeSearchMostVisitedUrl)); |
1017 if (!render_frame) | 1023 if (!render_frame) |
1018 return; | 1024 return; |
1019 | 1025 |
1020 if (args.Length() < 2 || !args[0]->IsNumber() || !args[1]->IsNumber()) { | 1026 if (args.Length() < 2 || !args[0]->IsNumber() || !args[1]->IsNumber()) { |
1021 ThrowInvalidParameters(args); | 1027 ThrowInvalidParameters(args); |
1022 return; | 1028 return; |
1023 } | 1029 } |
1024 | 1030 |
1025 DVLOG(1) << render_frame << " LogMostVisitedNavigation"; | 1031 DVLOG(1) << render_frame << " LogMostVisitedNavigation"; |
1026 | 1032 |
1027 if (args[1]->Uint32Value() <= static_cast<int>(ntp_tiles::TileSource::LAST)) { | 1033 if (args[1]->Uint32Value() <= static_cast<int>(ntp_tiles::TileSource::LAST) && |
1034 args[2]->Uint32Value() <= ntp_tiles::MAX_RECORDED_TILE_TYPE) { | |
1028 ntp_tiles::TileSource tile_source = | 1035 ntp_tiles::TileSource tile_source = |
1029 static_cast<ntp_tiles::TileSource>(args[1]->Uint32Value()); | 1036 static_cast<ntp_tiles::TileSource>(args[1]->Uint32Value()); |
1037 ntp_tiles::TileVisualType tile_type = | |
1038 static_cast<ntp_tiles::TileVisualType>(args[2]->Uint32Value()); | |
1030 SearchBox::Get(render_frame) | 1039 SearchBox::Get(render_frame) |
1031 ->LogMostVisitedNavigation(args[0]->IntegerValue(), tile_source); | 1040 ->LogMostVisitedNavigation(args[0]->IntegerValue(), tile_source, |
1041 tile_type); | |
1032 } | 1042 } |
1033 } | 1043 } |
1034 | 1044 |
1035 // static | 1045 // static |
1036 void SearchBoxExtensionWrapper::Paste( | 1046 void SearchBoxExtensionWrapper::Paste( |
1037 const v8::FunctionCallbackInfo<v8::Value>& args) { | 1047 const v8::FunctionCallbackInfo<v8::Value>& args) { |
1038 content::RenderFrame* render_frame = GetRenderFrame(); | 1048 content::RenderFrame* render_frame = GetRenderFrame(); |
1039 if (!render_frame) | 1049 if (!render_frame) |
1040 return; | 1050 return; |
1041 | 1051 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1091 ThrowInvalidParameters(args); | 1101 ThrowInvalidParameters(args); |
1092 return; | 1102 return; |
1093 } | 1103 } |
1094 | 1104 |
1095 DVLOG(1) << render_frame << " UndoMostVisitedDeletion"; | 1105 DVLOG(1) << render_frame << " UndoMostVisitedDeletion"; |
1096 SearchBox::Get(render_frame) | 1106 SearchBox::Get(render_frame) |
1097 ->UndoMostVisitedDeletion(args[0]->ToInteger()->Value()); | 1107 ->UndoMostVisitedDeletion(args[0]->ToInteger()->Value()); |
1098 } | 1108 } |
1099 | 1109 |
1100 } // namespace extensions_v8 | 1110 } // namespace extensions_v8 |
OLD | NEW |