Chromium Code Reviews| 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 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 640 // chrome-search://suggestion can call this function. | 641 // chrome-search://suggestion can call this function. |
| 641 static void GetSuggestionData( | 642 static void GetSuggestionData( |
| 642 const v8::FunctionCallbackInfo<v8::Value>& args); | 643 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 643 | 644 |
| 644 // Gets the raw data for a most visited item including its raw URL. | 645 // Gets the raw data for a most visited item including its raw URL. |
| 645 // GetRenderViewWithCheckedOrigin() enforces that only code in the origin | 646 // GetRenderViewWithCheckedOrigin() enforces that only code in the origin |
| 646 // chrome-search://most-visited can call this function. | 647 // chrome-search://most-visited can call this function. |
| 647 static void GetMostVisitedItemData( | 648 static void GetMostVisitedItemData( |
| 648 const v8::FunctionCallbackInfo<v8::Value>& args); | 649 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 649 | 650 |
| 651 // Logs information from the iframes on the NTP. | |
| 652 static void LogEvent(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 653 | |
| 650 // Gets whether the omnibox has focus or not. | 654 // Gets whether the omnibox has focus or not. |
| 651 static void IsFocused(const v8::FunctionCallbackInfo<v8::Value>& args); | 655 static void IsFocused(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 652 | 656 |
| 653 // Gets whether user input is in progress. | 657 // Gets whether user input is in progress. |
| 654 static void IsInputInProgress( | 658 static void IsInputInProgress( |
| 655 const v8::FunctionCallbackInfo<v8::Value>& args); | 659 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 656 | 660 |
| 657 private: | 661 private: |
| 658 DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper); | 662 DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper); |
| 659 }; | 663 }; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 732 if (name->Equals(v8::String::New("UndoMostVisitedDeletion"))) | 736 if (name->Equals(v8::String::New("UndoMostVisitedDeletion"))) |
| 733 return v8::FunctionTemplate::New(UndoMostVisitedDeletion); | 737 return v8::FunctionTemplate::New(UndoMostVisitedDeletion); |
| 734 if (name->Equals(v8::String::New("ShowBars"))) | 738 if (name->Equals(v8::String::New("ShowBars"))) |
| 735 return v8::FunctionTemplate::New(ShowBars); | 739 return v8::FunctionTemplate::New(ShowBars); |
| 736 if (name->Equals(v8::String::New("HideBars"))) | 740 if (name->Equals(v8::String::New("HideBars"))) |
| 737 return v8::FunctionTemplate::New(HideBars); | 741 return v8::FunctionTemplate::New(HideBars); |
| 738 if (name->Equals(v8::String::New("GetSuggestionData"))) | 742 if (name->Equals(v8::String::New("GetSuggestionData"))) |
| 739 return v8::FunctionTemplate::New(GetSuggestionData); | 743 return v8::FunctionTemplate::New(GetSuggestionData); |
| 740 if (name->Equals(v8::String::New("GetMostVisitedItemData"))) | 744 if (name->Equals(v8::String::New("GetMostVisitedItemData"))) |
| 741 return v8::FunctionTemplate::New(GetMostVisitedItemData); | 745 return v8::FunctionTemplate::New(GetMostVisitedItemData); |
| 746 if (name->Equals(v8::String::New("LogEvent"))) | |
| 747 return v8::FunctionTemplate::New(LogEvent); | |
| 742 if (name->Equals(v8::String::New("IsFocused"))) | 748 if (name->Equals(v8::String::New("IsFocused"))) |
| 743 return v8::FunctionTemplate::New(IsFocused); | 749 return v8::FunctionTemplate::New(IsFocused); |
| 744 if (name->Equals(v8::String::New("IsInputInProgress"))) | 750 if (name->Equals(v8::String::New("IsInputInProgress"))) |
| 745 return v8::FunctionTemplate::New(IsInputInProgress); | 751 return v8::FunctionTemplate::New(IsInputInProgress); |
| 746 return v8::Handle<v8::FunctionTemplate>(); | 752 return v8::Handle<v8::FunctionTemplate>(); |
| 747 } | 753 } |
| 748 | 754 |
| 749 // static | 755 // static |
| 750 content::RenderView* SearchBoxExtensionWrapper::GetRenderView() { | 756 content::RenderView* SearchBoxExtensionWrapper::GetRenderView() { |
| 751 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext(); | 757 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( | 1457 if (!SearchBox::Get(render_view)->GetMostVisitedItemWithID( |
| 1452 restricted_id, &mv_item)) { | 1458 restricted_id, &mv_item)) { |
| 1453 return; | 1459 return; |
| 1454 } | 1460 } |
| 1455 args.GetReturnValue().Set( | 1461 args.GetReturnValue().Set( |
| 1456 GenerateMostVisitedItem(render_view->GetRoutingID(), restricted_id, | 1462 GenerateMostVisitedItem(render_view->GetRoutingID(), restricted_id, |
| 1457 mv_item)); | 1463 mv_item)); |
| 1458 } | 1464 } |
| 1459 | 1465 |
| 1460 // static | 1466 // static |
| 1467 void SearchBoxExtensionWrapper::LogEvent( | |
| 1468 const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 1469 content::RenderView* render_view = GetRenderViewWithCheckedOrigin( | |
| 1470 GURL(chrome::kChromeSearchMostVisitedUrl)); | |
| 1471 if (!render_view) return; | |
| 1472 | |
| 1473 if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsNumber()) | |
| 1474 return; | |
| 1475 | |
| 1476 DVLOG(1) << render_view << " LogEvent"; | |
| 1477 | |
| 1478 std::string histogram_name = *v8::String::Utf8Value(args[0]->ToString()); | |
| 1479 int value = args[1]->IntegerValue(); | |
| 1480 | |
| 1481 if (!args[3]->IsNull() && args[3]->IsNumber()) { | |
| 1482 int pos = args[3]->IntegerValue(); | |
| 1483 if (histogram_name == "NewTabPage.NumberOfMouseOvers") { | |
| 1484 SearchBox::Get(render_view)->LogIframeHover(pos); | |
|
beaudoin
2013/06/22 01:14:53
Again, not sure you need the pos here.
annark1
2013/06/25 16:01:38
Done.
| |
| 1485 return; | |
| 1486 } | |
| 1487 } | |
| 1488 | |
| 1489 if (!args[2]->IsNull() && args[2]->IsNumber()) { | |
| 1490 int boundary = args[2]->IntegerValue(); | |
| 1491 UMA_HISTOGRAM_ENUMERATION(histogram_name, value, boundary); | |
| 1492 } | |
| 1493 } | |
| 1494 | |
| 1495 // static | |
| 1461 void SearchBoxExtensionWrapper::IsFocused( | 1496 void SearchBoxExtensionWrapper::IsFocused( |
| 1462 const v8::FunctionCallbackInfo<v8::Value>& args) { | 1497 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 1463 content::RenderView* render_view = GetRenderView(); | 1498 content::RenderView* render_view = GetRenderView(); |
| 1464 if (!render_view) return; | 1499 if (!render_view) return; |
| 1465 | 1500 |
| 1466 bool is_focused = SearchBox::Get(render_view)->is_focused(); | 1501 bool is_focused = SearchBox::Get(render_view)->is_focused(); |
| 1467 DVLOG(1) << render_view << " IsFocused: " << is_focused; | 1502 DVLOG(1) << render_view << " IsFocused: " << is_focused; |
| 1468 args.GetReturnValue().Set(is_focused); | 1503 args.GetReturnValue().Set(is_focused); |
| 1469 } | 1504 } |
| 1470 | 1505 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1560 Dispatch(frame, kDispatchInputCancelScript); | 1595 Dispatch(frame, kDispatchInputCancelScript); |
| 1561 } | 1596 } |
| 1562 | 1597 |
| 1563 // static | 1598 // static |
| 1564 void SearchBoxExtension::DispatchToggleVoiceSearch( | 1599 void SearchBoxExtension::DispatchToggleVoiceSearch( |
| 1565 WebKit::WebFrame* frame) { | 1600 WebKit::WebFrame* frame) { |
| 1566 Dispatch(frame, kDispatchToggleVoiceSearchScript); | 1601 Dispatch(frame, kDispatchToggleVoiceSearchScript); |
| 1567 } | 1602 } |
| 1568 | 1603 |
| 1569 } // namespace extensions_v8 | 1604 } // namespace extensions_v8 |
| OLD | NEW |