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/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 // chrome-search://suggestion can call this function. | 644 // chrome-search://suggestion can call this function. |
645 static void GetSuggestionData( | 645 static void GetSuggestionData( |
646 const v8::FunctionCallbackInfo<v8::Value>& args); | 646 const v8::FunctionCallbackInfo<v8::Value>& args); |
647 | 647 |
648 // Gets the raw data for a most visited item including its raw URL. | 648 // Gets the raw data for a most visited item including its raw URL. |
649 // GetRenderViewWithCheckedOrigin() enforces that only code in the origin | 649 // GetRenderViewWithCheckedOrigin() enforces that only code in the origin |
650 // chrome-search://most-visited can call this function. | 650 // chrome-search://most-visited can call this function. |
651 static void GetMostVisitedItemData( | 651 static void GetMostVisitedItemData( |
652 const v8::FunctionCallbackInfo<v8::Value>& args); | 652 const v8::FunctionCallbackInfo<v8::Value>& args); |
653 | 653 |
| 654 // Logs information from the iframes/titles on the NTP. |
| 655 static void LogEvent(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 656 |
654 // Gets whether the omnibox has focus or not. | 657 // Gets whether the omnibox has focus or not. |
655 static void IsFocused(const v8::FunctionCallbackInfo<v8::Value>& args); | 658 static void IsFocused(const v8::FunctionCallbackInfo<v8::Value>& args); |
656 | 659 |
657 // Gets whether user input is in progress. | 660 // Gets whether user input is in progress. |
658 static void IsInputInProgress( | 661 static void IsInputInProgress( |
659 const v8::FunctionCallbackInfo<v8::Value>& args); | 662 const v8::FunctionCallbackInfo<v8::Value>& args); |
660 | 663 |
661 private: | 664 private: |
662 DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper); | 665 DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper); |
663 }; | 666 }; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 if (name->Equals(v8::String::New("UndoMostVisitedDeletion"))) | 741 if (name->Equals(v8::String::New("UndoMostVisitedDeletion"))) |
739 return v8::FunctionTemplate::New(UndoMostVisitedDeletion); | 742 return v8::FunctionTemplate::New(UndoMostVisitedDeletion); |
740 if (name->Equals(v8::String::New("ShowBars"))) | 743 if (name->Equals(v8::String::New("ShowBars"))) |
741 return v8::FunctionTemplate::New(ShowBars); | 744 return v8::FunctionTemplate::New(ShowBars); |
742 if (name->Equals(v8::String::New("HideBars"))) | 745 if (name->Equals(v8::String::New("HideBars"))) |
743 return v8::FunctionTemplate::New(HideBars); | 746 return v8::FunctionTemplate::New(HideBars); |
744 if (name->Equals(v8::String::New("GetSuggestionData"))) | 747 if (name->Equals(v8::String::New("GetSuggestionData"))) |
745 return v8::FunctionTemplate::New(GetSuggestionData); | 748 return v8::FunctionTemplate::New(GetSuggestionData); |
746 if (name->Equals(v8::String::New("GetMostVisitedItemData"))) | 749 if (name->Equals(v8::String::New("GetMostVisitedItemData"))) |
747 return v8::FunctionTemplate::New(GetMostVisitedItemData); | 750 return v8::FunctionTemplate::New(GetMostVisitedItemData); |
| 751 if (name->Equals(v8::String::New("LogEvent"))) |
| 752 return v8::FunctionTemplate::New(LogEvent); |
748 if (name->Equals(v8::String::New("IsFocused"))) | 753 if (name->Equals(v8::String::New("IsFocused"))) |
749 return v8::FunctionTemplate::New(IsFocused); | 754 return v8::FunctionTemplate::New(IsFocused); |
750 if (name->Equals(v8::String::New("IsInputInProgress"))) | 755 if (name->Equals(v8::String::New("IsInputInProgress"))) |
751 return v8::FunctionTemplate::New(IsInputInProgress); | 756 return v8::FunctionTemplate::New(IsInputInProgress); |
752 return v8::Handle<v8::FunctionTemplate>(); | 757 return v8::Handle<v8::FunctionTemplate>(); |
753 } | 758 } |
754 | 759 |
755 // static | 760 // static |
756 content::RenderView* SearchBoxExtensionWrapper::GetRenderView() { | 761 content::RenderView* SearchBoxExtensionWrapper::GetRenderView() { |
757 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext(); | 762 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext(); |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1467 if (!SearchBox::Get(render_view)->GetMostVisitedItemWithID( | 1472 if (!SearchBox::Get(render_view)->GetMostVisitedItemWithID( |
1468 restricted_id, &mv_item)) { | 1473 restricted_id, &mv_item)) { |
1469 return; | 1474 return; |
1470 } | 1475 } |
1471 args.GetReturnValue().Set( | 1476 args.GetReturnValue().Set( |
1472 GenerateMostVisitedItem(render_view->GetRoutingID(), restricted_id, | 1477 GenerateMostVisitedItem(render_view->GetRoutingID(), restricted_id, |
1473 mv_item)); | 1478 mv_item)); |
1474 } | 1479 } |
1475 | 1480 |
1476 // static | 1481 // static |
| 1482 void SearchBoxExtensionWrapper::LogEvent( |
| 1483 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 1484 content::RenderView* render_view = GetRenderViewWithCheckedOrigin( |
| 1485 GURL(chrome::kChromeSearchMostVisitedUrl)); |
| 1486 if (!render_view) return; |
| 1487 |
| 1488 if (args.Length() < 1 || !args[0]->IsString()) |
| 1489 return; |
| 1490 |
| 1491 DVLOG(1) << render_view << " LogEvent"; |
| 1492 |
| 1493 std::string histogram_name = *v8::String::Utf8Value(args[0]->ToString()); |
| 1494 |
| 1495 if (histogram_name == "NewTabPage.NumberOfMouseOvers") |
| 1496 SearchBox::Get(render_view)->CountMouseover(); |
| 1497 else |
| 1498 DVLOG(1) << render_view << " Unsupported histogram name"; |
| 1499 } |
| 1500 |
| 1501 // static |
1477 void SearchBoxExtensionWrapper::IsFocused( | 1502 void SearchBoxExtensionWrapper::IsFocused( |
1478 const v8::FunctionCallbackInfo<v8::Value>& args) { | 1503 const v8::FunctionCallbackInfo<v8::Value>& args) { |
1479 content::RenderView* render_view = GetRenderView(); | 1504 content::RenderView* render_view = GetRenderView(); |
1480 if (!render_view) return; | 1505 if (!render_view) return; |
1481 | 1506 |
1482 bool is_focused = SearchBox::Get(render_view)->is_focused(); | 1507 bool is_focused = SearchBox::Get(render_view)->is_focused(); |
1483 DVLOG(1) << render_view << " IsFocused: " << is_focused; | 1508 DVLOG(1) << render_view << " IsFocused: " << is_focused; |
1484 args.GetReturnValue().Set(is_focused); | 1509 args.GetReturnValue().Set(is_focused); |
1485 } | 1510 } |
1486 | 1511 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1576 Dispatch(frame, kDispatchInputCancelScript); | 1601 Dispatch(frame, kDispatchInputCancelScript); |
1577 } | 1602 } |
1578 | 1603 |
1579 // static | 1604 // static |
1580 void SearchBoxExtension::DispatchToggleVoiceSearch( | 1605 void SearchBoxExtension::DispatchToggleVoiceSearch( |
1581 WebKit::WebFrame* frame) { | 1606 WebKit::WebFrame* frame) { |
1582 Dispatch(frame, kDispatchToggleVoiceSearchScript); | 1607 Dispatch(frame, kDispatchToggleVoiceSearchScript); |
1583 } | 1608 } |
1584 | 1609 |
1585 } // namespace extensions_v8 | 1610 } // namespace extensions_v8 |
OLD | NEW |