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 "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "base/metrics/histogram.h" | |
8 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
10 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/common/autocomplete_match_type.h" | 13 #include "chrome/common/autocomplete_match_type.h" |
13 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
14 #include "chrome/common/instant_types.h" | 15 #include "chrome/common/instant_types.h" |
15 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
16 #include "chrome/renderer/searchbox/searchbox.h" | 17 #include "chrome/renderer/searchbox/searchbox.h" |
17 #include "content/public/renderer/render_view.h" | 18 #include "content/public/renderer/render_view.h" |
(...skipping 26 matching lines...) Expand all Loading... | |
44 const char kCSSBackgroundRepeatX[] = "repeat-x"; | 45 const char kCSSBackgroundRepeatX[] = "repeat-x"; |
45 const char kCSSBackgroundRepeatY[] = "repeat-y"; | 46 const char kCSSBackgroundRepeatY[] = "repeat-y"; |
46 const char kCSSBackgroundRepeat[] = "repeat"; | 47 const char kCSSBackgroundRepeat[] = "repeat"; |
47 | 48 |
48 const char kThemeAttributionFormat[] = | 49 const char kThemeAttributionFormat[] = |
49 "chrome-search://theme/IDR_THEME_NTP_ATTRIBUTION?%s"; | 50 "chrome-search://theme/IDR_THEME_NTP_ATTRIBUTION?%s"; |
50 | 51 |
51 const char kLTRHtmlTextDirection[] = "ltr"; | 52 const char kLTRHtmlTextDirection[] = "ltr"; |
52 const char kRTLHtmlTextDirection[] = "rtl"; | 53 const char kRTLHtmlTextDirection[] = "rtl"; |
53 | 54 |
55 const int kDefaultUmaMin = 1; | |
56 const int kDefaultUmaMax = 1000000; | |
57 const int kDefaultUmaBucketCount = 50; | |
58 | |
54 // Converts a V8 value to a string16. | 59 // Converts a V8 value to a string16. |
55 string16 V8ValueToUTF16(v8::Handle<v8::Value> v) { | 60 string16 V8ValueToUTF16(v8::Handle<v8::Value> v) { |
56 v8::String::Value s(v); | 61 v8::String::Value s(v); |
57 return string16(reinterpret_cast<const char16*>(*s), s.length()); | 62 return string16(reinterpret_cast<const char16*>(*s), s.length()); |
58 } | 63 } |
59 | 64 |
60 // Converts string16 to V8 String. | 65 // Converts string16 to V8 String. |
61 v8::Handle<v8::String> UTF16ToV8String(const string16& s) { | 66 v8::Handle<v8::String> UTF16ToV8String(const string16& s) { |
62 return v8::String::New(reinterpret_cast<const uint16_t*>(s.data()), s.size()); | 67 return v8::String::New(reinterpret_cast<const uint16_t*>(s.data()), s.size()); |
63 } | 68 } |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
640 // chrome-search://suggestion can call this function. | 645 // chrome-search://suggestion can call this function. |
641 static void GetSuggestionData( | 646 static void GetSuggestionData( |
642 const v8::FunctionCallbackInfo<v8::Value>& args); | 647 const v8::FunctionCallbackInfo<v8::Value>& args); |
643 | 648 |
644 // Gets the raw data for a most visited item including its raw URL. | 649 // Gets the raw data for a most visited item including its raw URL. |
645 // GetRenderViewWithCheckedOrigin() enforces that only code in the origin | 650 // GetRenderViewWithCheckedOrigin() enforces that only code in the origin |
646 // chrome-search://most-visited can call this function. | 651 // chrome-search://most-visited can call this function. |
647 static void GetMostVisitedItemData( | 652 static void GetMostVisitedItemData( |
648 const v8::FunctionCallbackInfo<v8::Value>& args); | 653 const v8::FunctionCallbackInfo<v8::Value>& args); |
649 | 654 |
655 // Logs information from the iframes on the NTP. | |
656 static void LogEvent(const v8::FunctionCallbackInfo<v8::Value>& args); | |
657 | |
650 // Gets whether the omnibox has focus or not. | 658 // Gets whether the omnibox has focus or not. |
651 static void IsFocused(const v8::FunctionCallbackInfo<v8::Value>& args); | 659 static void IsFocused(const v8::FunctionCallbackInfo<v8::Value>& args); |
652 | 660 |
653 // Gets whether user input is in progress. | 661 // Gets whether user input is in progress. |
654 static void IsInputInProgress( | 662 static void IsInputInProgress( |
655 const v8::FunctionCallbackInfo<v8::Value>& args); | 663 const v8::FunctionCallbackInfo<v8::Value>& args); |
656 | 664 |
657 private: | 665 private: |
658 DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper); | 666 DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper); |
659 }; | 667 }; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
732 if (name->Equals(v8::String::New("UndoMostVisitedDeletion"))) | 740 if (name->Equals(v8::String::New("UndoMostVisitedDeletion"))) |
733 return v8::FunctionTemplate::New(UndoMostVisitedDeletion); | 741 return v8::FunctionTemplate::New(UndoMostVisitedDeletion); |
734 if (name->Equals(v8::String::New("ShowBars"))) | 742 if (name->Equals(v8::String::New("ShowBars"))) |
735 return v8::FunctionTemplate::New(ShowBars); | 743 return v8::FunctionTemplate::New(ShowBars); |
736 if (name->Equals(v8::String::New("HideBars"))) | 744 if (name->Equals(v8::String::New("HideBars"))) |
737 return v8::FunctionTemplate::New(HideBars); | 745 return v8::FunctionTemplate::New(HideBars); |
738 if (name->Equals(v8::String::New("GetSuggestionData"))) | 746 if (name->Equals(v8::String::New("GetSuggestionData"))) |
739 return v8::FunctionTemplate::New(GetSuggestionData); | 747 return v8::FunctionTemplate::New(GetSuggestionData); |
740 if (name->Equals(v8::String::New("GetMostVisitedItemData"))) | 748 if (name->Equals(v8::String::New("GetMostVisitedItemData"))) |
741 return v8::FunctionTemplate::New(GetMostVisitedItemData); | 749 return v8::FunctionTemplate::New(GetMostVisitedItemData); |
750 if (name->Equals(v8::String::New("LogEvent"))) | |
751 return v8::FunctionTemplate::New(LogEvent); | |
742 if (name->Equals(v8::String::New("IsFocused"))) | 752 if (name->Equals(v8::String::New("IsFocused"))) |
743 return v8::FunctionTemplate::New(IsFocused); | 753 return v8::FunctionTemplate::New(IsFocused); |
744 if (name->Equals(v8::String::New("IsInputInProgress"))) | 754 if (name->Equals(v8::String::New("IsInputInProgress"))) |
745 return v8::FunctionTemplate::New(IsInputInProgress); | 755 return v8::FunctionTemplate::New(IsInputInProgress); |
746 return v8::Handle<v8::FunctionTemplate>(); | 756 return v8::Handle<v8::FunctionTemplate>(); |
747 } | 757 } |
748 | 758 |
749 // static | 759 // static |
750 content::RenderView* SearchBoxExtensionWrapper::GetRenderView() { | 760 content::RenderView* SearchBoxExtensionWrapper::GetRenderView() { |
751 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext(); | 761 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext(); |
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1451 if (!SearchBox::Get(render_view)->GetMostVisitedItemWithID( | 1461 if (!SearchBox::Get(render_view)->GetMostVisitedItemWithID( |
1452 restricted_id, &mv_item)) { | 1462 restricted_id, &mv_item)) { |
1453 return; | 1463 return; |
1454 } | 1464 } |
1455 args.GetReturnValue().Set( | 1465 args.GetReturnValue().Set( |
1456 GenerateMostVisitedItem(render_view->GetRoutingID(), restricted_id, | 1466 GenerateMostVisitedItem(render_view->GetRoutingID(), restricted_id, |
1457 mv_item)); | 1467 mv_item)); |
1458 } | 1468 } |
1459 | 1469 |
1460 // static | 1470 // static |
1471 void SearchBoxExtensionWrapper::LogEvent( | |
1472 const v8::FunctionCallbackInfo<v8::Value>& args) { | |
1473 content::RenderView* render_view = GetRenderViewWithCheckedOrigin( | |
1474 GURL(chrome::kChromeSearchMostVisitedUrl)); | |
1475 if (!render_view) return; | |
1476 | |
1477 if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsNumber()) | |
1478 return; | |
1479 | |
1480 DVLOG(1) << render_view << " LogEvent"; | |
1481 | |
1482 std::string histogram_name = *v8::String::Utf8Value(args[0]->ToString()); | |
1483 int value = args[1]->IntegerValue(); | |
1484 | |
1485 if (histogram_name == "NewTabPage.NumberOfMouseOvers") { | |
1486 SearchBox::Get(render_view)->LogIframeHover(); | |
1487 return; | |
1488 } | |
1489 | |
1490 if (!args[2]->IsNull() && args[2]->IsNumber()) { | |
Jered
2013/06/26 16:37:57
What is up with this code? I don't see where it's
annark1
2013/06/28 15:30:49
This was intended to make the LogEvent function mo
| |
1491 int boundary = args[2]->IntegerValue(); | |
1492 int bucket_count = boundary; | |
1493 while (bucket_count >= 100) { | |
1494 bucket_count /= 10; | |
1495 } | |
1496 // As |histogram_name| may change between calls, the | |
1497 // UMA_HISTOGRAM_ENUMERATION macro cannot be used here. | |
1498 base::HistogramBase* counter = | |
1499 base::LinearHistogram::FactoryGet( | |
1500 histogram_name, 1, boundary, bucket_count + 1, | |
1501 base::HistogramBase::kUmaTargetedHistogramFlag); | |
1502 counter->Add(value); | |
1503 } else { | |
1504 // See above comment regarding UMA macros. | |
1505 base::HistogramBase* counter = | |
1506 base::Histogram::FactoryGet( | |
1507 histogram_name, | |
1508 kDefaultUmaMin, | |
1509 kDefaultUmaMax, | |
1510 kDefaultUmaBucketCount, | |
1511 base::HistogramBase::kUmaTargetedHistogramFlag); | |
1512 counter->Add(value); | |
1513 } | |
1514 } | |
1515 | |
1516 // static | |
1461 void SearchBoxExtensionWrapper::IsFocused( | 1517 void SearchBoxExtensionWrapper::IsFocused( |
1462 const v8::FunctionCallbackInfo<v8::Value>& args) { | 1518 const v8::FunctionCallbackInfo<v8::Value>& args) { |
1463 content::RenderView* render_view = GetRenderView(); | 1519 content::RenderView* render_view = GetRenderView(); |
1464 if (!render_view) return; | 1520 if (!render_view) return; |
1465 | 1521 |
1466 bool is_focused = SearchBox::Get(render_view)->is_focused(); | 1522 bool is_focused = SearchBox::Get(render_view)->is_focused(); |
1467 DVLOG(1) << render_view << " IsFocused: " << is_focused; | 1523 DVLOG(1) << render_view << " IsFocused: " << is_focused; |
1468 args.GetReturnValue().Set(is_focused); | 1524 args.GetReturnValue().Set(is_focused); |
1469 } | 1525 } |
1470 | 1526 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1560 Dispatch(frame, kDispatchInputCancelScript); | 1616 Dispatch(frame, kDispatchInputCancelScript); |
1561 } | 1617 } |
1562 | 1618 |
1563 // static | 1619 // static |
1564 void SearchBoxExtension::DispatchToggleVoiceSearch( | 1620 void SearchBoxExtension::DispatchToggleVoiceSearch( |
1565 WebKit::WebFrame* frame) { | 1621 WebKit::WebFrame* frame) { |
1566 Dispatch(frame, kDispatchToggleVoiceSearchScript); | 1622 Dispatch(frame, kDispatchToggleVoiceSearchScript); |
1567 } | 1623 } |
1568 | 1624 |
1569 } // namespace extensions_v8 | 1625 } // namespace extensions_v8 |
OLD | NEW |