Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: chrome/browser/automation/automation_provider.cc

Issue 13130: Fix issue 5079: Incorrect "Active match ordinal" count during Find-in-page... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/automation/automation_provider.h" 5 #include "chrome/browser/automation/automation_provider.h"
6 6
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "chrome/app/chrome_dll_resource.h" 8 #include "chrome/app/chrome_dll_resource.h"
9 #include "chrome/browser/automation/automation_provider_list.h" 9 #include "chrome/browser/automation/automation_provider_list.h"
10 #include "chrome/browser/automation/ui_controls.h" 10 #include "chrome/browser/automation/ui_controls.h"
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 int32 routing_id_; 403 int32 routing_id_;
404 }; 404 };
405 405
406 class FindInPageNotificationObserver : public NotificationObserver { 406 class FindInPageNotificationObserver : public NotificationObserver {
407 public: 407 public:
408 FindInPageNotificationObserver(AutomationProvider* automation, 408 FindInPageNotificationObserver(AutomationProvider* automation,
409 TabContents* parent_tab, 409 TabContents* parent_tab,
410 int32 routing_id) 410 int32 routing_id)
411 : automation_(automation), 411 : automation_(automation),
412 parent_tab_(parent_tab), 412 parent_tab_(parent_tab),
413 routing_id_(routing_id) { 413 routing_id_(routing_id),
414 active_match_ordinal_(-1) {
414 NotificationService::current()-> 415 NotificationService::current()->
415 AddObserver(this, NOTIFY_FIND_RESULT_AVAILABLE, 416 AddObserver(this, NOTIFY_FIND_RESULT_AVAILABLE,
416 Source<TabContents>(parent_tab_)); 417 Source<TabContents>(parent_tab_));
417 } 418 }
418 419
419 ~FindInPageNotificationObserver() { 420 ~FindInPageNotificationObserver() {
420 Unregister(); 421 Unregister();
421 } 422 }
422 423
423 void Unregister() { 424 void Unregister() {
424 NotificationService::current()-> 425 NotificationService::current()->
425 RemoveObserver(this, NOTIFY_FIND_RESULT_AVAILABLE, 426 RemoveObserver(this, NOTIFY_FIND_RESULT_AVAILABLE,
426 Source<TabContents>(parent_tab_)); 427 Source<TabContents>(parent_tab_));
427 } 428 }
428 429
429 virtual void Observe(NotificationType type, const NotificationSource& source, 430 virtual void Observe(NotificationType type, const NotificationSource& source,
430 const NotificationDetails& details) { 431 const NotificationDetails& details) {
431 if (type == NOTIFY_FIND_RESULT_AVAILABLE) { 432 if (type == NOTIFY_FIND_RESULT_AVAILABLE) {
432 Details<FindNotificationDetails> find_details(details); 433 Details<FindNotificationDetails> find_details(details);
433 if (find_details->request_id() == kFindInPageRequestId) { 434 if (find_details->request_id() == kFindInPageRequestId) {
435 // We get multiple responses and one of those will contain the ordinal.
436 // This message comes to us before the final update is sent.
437 if (find_details->active_match_ordinal() > -1)
438 active_match_ordinal_ = find_details->active_match_ordinal();
434 if (find_details->final_update()) { 439 if (find_details->final_update()) {
435 automation_->Send(new AutomationMsg_FindInPageResponse(routing_id_, 440 automation_->Send(new AutomationMsg_FindInPageResponse2(routing_id_,
441 active_match_ordinal_,
436 find_details->number_of_matches())); 442 find_details->number_of_matches()));
437 } else { 443 } else {
438 DLOG(INFO) << "Ignoring, since we only care about the final message"; 444 DLOG(INFO) << "Ignoring, since we only care about the final message";
439 } 445 }
440 } 446 }
441 } else { 447 } else {
442 NOTREACHED(); 448 NOTREACHED();
443 } 449 }
444 } 450 }
445 451
446 // The Find mechanism is over asynchronous IPC, so a search is kicked off and 452 // The Find mechanism is over asynchronous IPC, so a search is kicked off and
447 // we wait for notification to find out what the results are. As the user is 453 // we wait for notification to find out what the results are. As the user is
448 // typing, new search requests can be issued and the Request ID helps us make 454 // typing, new search requests can be issued and the Request ID helps us make
449 // sense of whether this is the current request or an old one. The unit tests, 455 // sense of whether this is the current request or an old one. The unit tests,
450 // however, which uses this constant issues only one search at a time, so we 456 // however, which uses this constant issues only one search at a time, so we
451 // don't need a rolling id to identify each search. But, we still need to 457 // don't need a rolling id to identify each search. But, we still need to
452 // specify one, so we just use a fixed one - its value does not matter. 458 // specify one, so we just use a fixed one - its value does not matter.
453 static const int kFindInPageRequestId; 459 static const int kFindInPageRequestId;
454 private: 460 private:
455 AutomationProvider* automation_; 461 AutomationProvider* automation_;
456 TabContents* parent_tab_; 462 TabContents* parent_tab_;
457 int32 routing_id_; 463 int32 routing_id_;
464 // We will at some point (before final update) be notified of the ordinal and
465 // we need to preserve it so we can send it later.
466 int active_match_ordinal_;
458 }; 467 };
459 468
460 const int FindInPageNotificationObserver::kFindInPageRequestId = -1; 469 const int FindInPageNotificationObserver::kFindInPageRequestId = -1;
461 470
462 class DomOperationNotificationObserver : public NotificationObserver { 471 class DomOperationNotificationObserver : public NotificationObserver {
463 public: 472 public:
464 explicit DomOperationNotificationObserver(AutomationProvider* automation) 473 explicit DomOperationNotificationObserver(AutomationProvider* automation)
465 : automation_(automation) { 474 : automation_(automation) {
466 NotificationService::current()-> 475 NotificationService::current()->
467 AddObserver(this, NOTIFY_DOM_OPERATION_RESPONSE, 476 AddObserver(this, NOTIFY_DOM_OPERATION_RESPONSE,
(...skipping 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1705 1714
1706 Send(new AutomationMsg_ConstrainedWindowBoundsResponse(message.routing_id(), 1715 Send(new AutomationMsg_ConstrainedWindowBoundsResponse(message.routing_id(),
1707 exists, rect)); 1716 exists, rect));
1708 } 1717 }
1709 1718
1710 void AutomationProvider::HandleFindInPageRequest( 1719 void AutomationProvider::HandleFindInPageRequest(
1711 const IPC::Message& message, int handle, const std::wstring& find_request, 1720 const IPC::Message& message, int handle, const std::wstring& find_request,
1712 int forward, int match_case) { 1721 int forward, int match_case) {
1713 NOTREACHED() << "This function has been deprecated." 1722 NOTREACHED() << "This function has been deprecated."
1714 << "Please use HandleFindRequest instead."; 1723 << "Please use HandleFindRequest instead.";
1715 Send(new AutomationMsg_FindInPageResponse(message.routing_id(), -1)); 1724 Send(new AutomationMsg_FindInPageResponse2(message.routing_id(), -1, -1));
1716 return; 1725 return;
1717 } 1726 }
1718 1727
1719 void AutomationProvider::HandleFindRequest(const IPC::Message& message, 1728 void AutomationProvider::HandleFindRequest(const IPC::Message& message,
1720 int handle, const FindInPageRequest& request) { 1729 int handle, const FindInPageRequest& request) {
1721 if (!tab_tracker_->ContainsHandle(handle)) { 1730 if (!tab_tracker_->ContainsHandle(handle)) {
1722 Send(new AutomationMsg_FindInPageResponse(message.routing_id(), -1)); 1731 Send(new AutomationMsg_FindInPageResponse2(message.routing_id(), -1, -1));
1723 return; 1732 return;
1724 } 1733 }
1725 1734
1726 NavigationController* nav = tab_tracker_->GetResource(handle); 1735 NavigationController* nav = tab_tracker_->GetResource(handle);
1727 TabContents* tab_contents = nav->active_contents(); 1736 TabContents* tab_contents = nav->active_contents();
1728 1737
1729 find_in_page_observer_.reset(new 1738 find_in_page_observer_.reset(new
1730 FindInPageNotificationObserver(this, tab_contents, message.routing_id())); 1739 FindInPageNotificationObserver(this, tab_contents, message.routing_id()));
1731 1740
1732 // The find in page dialog must be up for us to get the notification that the 1741 // The find in page dialog must be up for us to get the notification that the
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
2438 int value) { 2447 int value) {
2439 bool success = false; 2448 bool success = false;
2440 if (browser_tracker_->ContainsHandle(handle)) { 2449 if (browser_tracker_->ContainsHandle(handle)) {
2441 Browser* browser = browser_tracker_->GetResource(handle); 2450 Browser* browser = browser_tracker_->GetResource(handle);
2442 browser->profile()->GetPrefs()->SetInteger(name.c_str(), value); 2451 browser->profile()->GetPrefs()->SetInteger(name.c_str(), value);
2443 success = true; 2452 success = true;
2444 } 2453 }
2445 Send(new AutomationMsg_SetIntPreferenceResponse(message.routing_id(), 2454 Send(new AutomationMsg_SetIntPreferenceResponse(message.routing_id(),
2446 success)); 2455 success));
2447 } 2456 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/views/find_bar_win_uitest.cc » ('j') | chrome/test/automation/automation_messages_internal.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698