From 86a7d3ca7f467269213f8ce08ab138bbed5326f2 Mon Sep 17 00:00:00 2001 From: "avi@chromium.org" Date: Mon, 12 Sep 2011 16:45:32 +0000 Subject: Move TextInputClient from chrome to content. BUG=95573 TEST=dictionary popup still works Review URL: http://codereview.chromium.org/7844003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100703 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/chrome_content_browser_client.cc | 4 - .../renderer_host/render_widget_host_view_mac.mm | 2 +- .../browser/renderer_host/text_input_client_mac.h | 86 --------- .../browser/renderer_host/text_input_client_mac.mm | 126 ------------ .../text_input_client_mac_unittest.mm | 212 --------------------- .../text_input_client_message_filter.h | 45 ----- .../text_input_client_message_filter.mm | 67 ------- chrome/chrome_browser.gypi | 4 - chrome/chrome_common.gypi | 1 - chrome/chrome_renderer.gypi | 2 - chrome/chrome_tests.gypi | 2 +- chrome/common/common_message_generator.h | 1 - chrome/common/text_input_client_messages.h | 53 ------ chrome/renderer/chrome_content_renderer_client.cc | 5 - chrome/renderer/text_input_client_observer.cc | 70 ------- chrome/renderer/text_input_client_observer.h | 41 ---- 16 files changed, 2 insertions(+), 719 deletions(-) delete mode 100644 chrome/browser/renderer_host/text_input_client_mac.h delete mode 100644 chrome/browser/renderer_host/text_input_client_mac.mm delete mode 100644 chrome/browser/renderer_host/text_input_client_mac_unittest.mm delete mode 100644 chrome/browser/renderer_host/text_input_client_message_filter.h delete mode 100644 chrome/browser/renderer_host/text_input_client_message_filter.mm delete mode 100644 chrome/common/text_input_client_messages.h delete mode 100644 chrome/renderer/text_input_client_observer.cc delete mode 100644 chrome/renderer/text_input_client_observer.h (limited to 'chrome') diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index ce7a52c..1df60b6 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -34,7 +34,6 @@ #include "chrome/browser/profiles/profile_io_data.h" #include "chrome/browser/renderer_host/chrome_render_message_filter.h" #include "chrome/browser/renderer_host/chrome_render_view_host_observer.h" -#include "chrome/browser/renderer_host/text_input_client_message_filter.h" #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h" #include "chrome/browser/speech/chrome_speech_input_manager.h" #include "chrome/browser/spellchecker/spellcheck_message_filter.h" @@ -173,9 +172,6 @@ void ChromeContentBrowserClient::BrowserRenderProcessHostCreated( host->channel()->AddFilter( new SearchProviderInstallStateMessageFilter(id, profile)); host->channel()->AddFilter(new SpellCheckMessageFilter(id)); -#if defined(OS_MACOSX) - host->channel()->AddFilter(new TextInputClientMessageFilter(host->id())); -#endif host->Send(new ChromeViewMsg_SetIsIncognitoProcess( profile->IsOffTheRecord())); diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.mm b/chrome/browser/renderer_host/render_widget_host_view_mac.mm index 5d095db..dcc3988 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm @@ -20,7 +20,6 @@ #include "base/sys_string_conversions.h" #include "chrome/browser/mac/closure_blocks_leopard_compat.h" #import "chrome/browser/renderer_host/accelerated_plugin_view_mac.h" -#import "chrome/browser/renderer_host/text_input_client_mac.h" #include "chrome/browser/spellchecker/spellchecker_platform_engine.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" @@ -40,6 +39,7 @@ #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/renderer_host/render_view_host_observer.h" #include "content/browser/renderer_host/render_widget_host.h" +#import "content/browser/renderer_host/text_input_client_mac.h" #include "content/common/edit_command.h" #include "content/common/gpu/gpu_messages.h" #include "content/common/native_web_keyboard_event.h" diff --git a/chrome/browser/renderer_host/text_input_client_mac.h b/chrome/browser/renderer_host/text_input_client_mac.h deleted file mode 100644 index 00c2e29..0000000 --- a/chrome/browser/renderer_host/text_input_client_mac.h +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_RENDERER_HOST_TEXT_INPUT_CLIENT_MAC_H_ -#define CHROME_BROWSER_RENDERER_HOST_TEXT_INPUT_CLIENT_MAC_H_ - -#import - -#include "base/memory/scoped_nsobject.h" -#include "base/synchronization/condition_variable.h" -#include "base/synchronization/lock.h" -#include "ui/gfx/point.h" - -template struct DefaultSingletonTraits; - -class RenderWidgetHost; - -// This class helps with the Mac OS X dictionary popup. For the design overview, -// look at this document: -// http://dev.chromium.org/developers/design-documents/system-dictionary-pop-up-architecture -// -// This service is used to marshall information for these three methods that are -// implemented in RenderWidgetHostViewMac: -// -[NSTextInput characterIndexForPoint:] -// -[NSTextInput attributedSubstringFromRange:] -// -[NSTextInput firstRectForCharacterRange:] -// -// Because these methods are part of a synchronous system API, implementing them -// requires getting information from the renderer synchronously. Rather than -// using an actual sync IPC message, a normal async ViewMsg is used with a lock -// and condition (managed by this service). -class TextInputClientMac { - public: - // Returns the singleton instance. - static TextInputClientMac* GetInstance(); - - // Each of the three methods mentioned above has an associated pair of methods - // to get data from the renderer. The Get*() methods block the calling thread - // (always the UI thread) with a short timeout after the async message has - // been sent to the renderer to lookup the information needed to respond to - // the system. The Set*AndSignal() methods store the looked up information in - // this service and signal the condition to allow the Get*() methods to - // unlock and return that stored value. - // - // Returns NSNotFound if the request times out or is not completed. - NSUInteger GetCharacterIndexAtPoint(RenderWidgetHost* rwh, gfx::Point point); - // Returns nil if the request times out or is completed. - NSAttributedString* GetAttributedSubstringFromRange(RenderWidgetHost* rwh, - NSRange range); - // Returns NSZeroRect if the request times out or is not completed. The result - // is in WebKit coordinates. - NSRect GetFirstRectForRange(RenderWidgetHost* rwh, NSRange range); - - // When the renderer sends the ViewHostMsg reply, the RenderMessageFilter will - // call the corresponding method on the IO thread to unlock the condition and - // allow the Get*() methods to continue/return. - void SetCharacterIndexAndSignal(NSUInteger index); - void SetFirstRectAndSignal(NSRect first_rect); - void SetSubstringAndSignal(NSAttributedString* string); - - private: - friend struct DefaultSingletonTraits; - TextInputClientMac(); - ~TextInputClientMac(); - - // The critical sections that the Condition guards are in Get*() methods. - // These methods lock the internal condition for use before the asynchronous - // message is sent to the renderer to lookup the required information. These - // are only used on the UI thread. - void BeforeRequest(); - // Called at the end of a critical section. This will release the lock and - // condition. - void AfterRequest(); - - NSUInteger character_index_; - NSRect first_rect_; - scoped_nsobject substring_; - - base::Lock lock_; - base::ConditionVariable condition_; - - DISALLOW_COPY_AND_ASSIGN(TextInputClientMac); -}; - -#endif // CHROME_BROWSER_RENDERER_HOST_TEXT_INPUT_CLIENT_MAC_H_ diff --git a/chrome/browser/renderer_host/text_input_client_mac.mm b/chrome/browser/renderer_host/text_input_client_mac.mm deleted file mode 100644 index a8f7c75..0000000 --- a/chrome/browser/renderer_host/text_input_client_mac.mm +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#import "chrome/browser/renderer_host/text_input_client_mac.h" - -#include "base/memory/singleton.h" -#include "base/metrics/histogram.h" -#include "base/time.h" -#include "chrome/common/text_input_client_messages.h" -#include "content/browser/renderer_host/render_widget_host.h" - -// The amount of time in milliseconds that the browser process will wait for a -// response from the renderer. -// TODO(rsesek): Using the histogram data, find the best upper-bound for this -// value. -const float kWaitTimeout = 1500; - -TextInputClientMac::TextInputClientMac() - : character_index_(NSNotFound), - lock_(), - condition_(&lock_) { -} - -TextInputClientMac::~TextInputClientMac() { -} - -// static -TextInputClientMac* TextInputClientMac::GetInstance() { - return Singleton::get(); -} - -NSUInteger TextInputClientMac::GetCharacterIndexAtPoint(RenderWidgetHost* rwh, - gfx::Point point) { - base::TimeTicks start = base::TimeTicks::Now(); - - BeforeRequest(); - rwh->Send(new TextInputClientMsg_CharacterIndexForPoint(rwh->routing_id(), - point)); - condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); - AfterRequest(); - - base::TimeDelta delta(base::TimeTicks::Now() - start); - UMA_HISTOGRAM_TIMES("TextInputClient.CharacterIndex", - delta * base::Time::kMicrosecondsPerMillisecond); - - return character_index_; -} - -NSRect TextInputClientMac::GetFirstRectForRange(RenderWidgetHost* rwh, - NSRange range) { - base::TimeTicks start = base::TimeTicks::Now(); - - BeforeRequest(); - rwh->Send(new TextInputClientMsg_FirstRectForCharacterRange(rwh->routing_id(), - ui::Range(range))); - condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); - AfterRequest(); - - base::TimeDelta delta(base::TimeTicks::Now() - start); - UMA_HISTOGRAM_TIMES("TextInputClient.FirstRect", - delta * base::Time::kMicrosecondsPerMillisecond); - - return first_rect_; -} - -NSAttributedString* TextInputClientMac::GetAttributedSubstringFromRange( - RenderWidgetHost* rwh, - NSRange range) { - base::TimeTicks start = base::TimeTicks::Now(); - - BeforeRequest(); - rwh->Send(new TextInputClientMsg_StringForRange(rwh->routing_id(), - ui::Range(range))); - condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); - AfterRequest(); - - base::TimeDelta delta(base::TimeTicks::Now() - start); - UMA_HISTOGRAM_TIMES("TextInputClient.Substring", - delta * base::Time::kMicrosecondsPerMillisecond); - - - // Lookup.framework calls this method repeatedly and expects that repeated - // calls don't deallocate previous results immediately. Returning an - // autoreleased string is better convention anyway. - return [[substring_.get() retain] autorelease]; -} - -void TextInputClientMac::SetCharacterIndexAndSignal(NSUInteger index) { - lock_.Acquire(); - character_index_ = index; - lock_.Release(); - condition_.Signal(); -} - -void TextInputClientMac::SetFirstRectAndSignal(NSRect first_rect) { - lock_.Acquire(); - first_rect_ = first_rect; - lock_.Release(); - condition_.Signal(); -} - -void TextInputClientMac::SetSubstringAndSignal(NSAttributedString* string) { - lock_.Acquire(); - substring_.reset([string copy]); - lock_.Release(); - condition_.Signal(); -} - -void TextInputClientMac::BeforeRequest() { - base::TimeTicks start = base::TimeTicks::Now(); - - lock_.Acquire(); - - base::TimeDelta delta(base::TimeTicks::Now() - start); - UMA_HISTOGRAM_TIMES("TextInputClient.LockWait", - delta * base::Time::kMicrosecondsPerMillisecond); - - character_index_ = NSNotFound; - first_rect_ = NSZeroRect; - substring_.reset(); -} - -void TextInputClientMac::AfterRequest() { - lock_.Release(); -} diff --git a/chrome/browser/renderer_host/text_input_client_mac_unittest.mm b/chrome/browser/renderer_host/text_input_client_mac_unittest.mm deleted file mode 100644 index 2ea2735..0000000 --- a/chrome/browser/renderer_host/text_input_client_mac_unittest.mm +++ /dev/null @@ -1,212 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#import "chrome/browser/renderer_host/text_input_client_mac.h" - -#include "base/bind.h" -#include "base/message_loop.h" -#include "base/threading/thread.h" -#include "chrome/browser/renderer_host/text_input_client_message_filter.h" -#include "chrome/common/text_input_client_messages.h" -#include "chrome/test/base/testing_profile.h" -#include "content/browser/renderer_host/mock_render_process_host.h" -#include "content/browser/renderer_host/render_process_host.h" -#include "content/browser/renderer_host/render_widget_host.h" -#include "ipc/ipc_test_sink.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "testing/gtest_mac.h" - -namespace { - -const int64 kTaskDelayMs = 200; - -// This test does not test the WebKit side of the dictionary system (which -// performs the actual data fetching), but rather this just tests that the -// service's signaling system works. -class TextInputClientMacTest : public testing::Test { - public: - TextInputClientMacTest() - : message_loop_(MessageLoop::TYPE_UI), - profile_(), - process_factory_(), - widget_(process_factory_.CreateRenderProcessHost(&profile_), 1), - thread_("TextInputClientMacTestThread") {} - - // Accessor for the TextInputClientMac instance. - TextInputClientMac* service() { - return TextInputClientMac::GetInstance(); - } - - // Helper method to post a task on the testing thread's MessageLoop after - // a short delay. - void PostTask(const tracked_objects::Location& from_here, - const base::Closure& task, const int64 delay = kTaskDelayMs) { - thread_.message_loop()->PostDelayedTask(from_here, task, delay); - } - - RenderWidgetHost* widget() { - return &widget_; - } - - IPC::TestSink& ipc_sink() { - return static_cast(widget()->process())->sink(); - } - - private: - friend class ScopedTestingThread; - - MessageLoop message_loop_; - TestingProfile profile_; - - // Gets deleted when the last RWH in the "process" gets destroyed. - MockRenderProcessHostFactory process_factory_; - RenderWidgetHost widget_; - - base::Thread thread_; -}; - -//////////////////////////////////////////////////////////////////////////////// - -// Helper class that Start()s and Stop()s a thread according to the scope of the -// object. -class ScopedTestingThread { - public: - ScopedTestingThread(TextInputClientMacTest* test) : thread_(test->thread_) { - thread_.Start(); - } - ~ScopedTestingThread() { - thread_.Stop(); - } - - private: - base::Thread& thread_; -}; - -// Adapter for OnMessageReceived to ignore return type so it can be posted -// to a MessageLoop. -void CallOnMessageReceived(scoped_refptr filter, - const IPC::Message& message, - bool* message_was_ok) { - filter->OnMessageReceived(message, message_was_ok); -} - -// Test Cases ////////////////////////////////////////////////////////////////// - -TEST_F(TextInputClientMacTest, GetCharacterIndex) { - ScopedTestingThread thread(this); - const NSUInteger kSuccessValue = 42; - - PostTask(FROM_HERE, - base::Bind(&TextInputClientMac::SetCharacterIndexAndSignal, - base::Unretained(service()), kSuccessValue)); - NSUInteger index = service()->GetCharacterIndexAtPoint( - widget(), gfx::Point(2, 2)); - - EXPECT_EQ(1U, ipc_sink().message_count()); - EXPECT_TRUE(ipc_sink().GetUniqueMessageMatching( - TextInputClientMsg_CharacterIndexForPoint::ID)); - EXPECT_EQ(kSuccessValue, index); -} - -TEST_F(TextInputClientMacTest, TimeoutCharacterIndex) { - NSUInteger index = service()->GetCharacterIndexAtPoint( - widget(), gfx::Point(2, 2)); - EXPECT_EQ(1U, ipc_sink().message_count()); - EXPECT_TRUE(ipc_sink().GetUniqueMessageMatching( - TextInputClientMsg_CharacterIndexForPoint::ID)); - EXPECT_EQ(NSNotFound, index); -} - -TEST_F(TextInputClientMacTest, NotFoundCharacterIndex) { - ScopedTestingThread thread(this); - const NSUInteger kPreviousValue = 42; - const size_t kNotFoundValue = static_cast(-1); - - // Set an arbitrary value to ensure the index is not |NSNotFound|. - PostTask(FROM_HERE, - base::Bind(&TextInputClientMac::SetCharacterIndexAndSignal, - base::Unretained(service()), kPreviousValue)); - - scoped_refptr filter( - new TextInputClientMessageFilter(widget()->process()->id())); - scoped_ptr message( - new TextInputClientReplyMsg_GotCharacterIndexForPoint( - widget()->routing_id(), kNotFoundValue)); - bool message_ok = true; - // Set |WTF::notFound| to the index |kTaskDelayMs| after the previous - // setting. - PostTask(FROM_HERE, - base::Bind(&CallOnMessageReceived, filter, *message, &message_ok), - kTaskDelayMs * 2); - - NSUInteger index = service()->GetCharacterIndexAtPoint( - widget(), gfx::Point(2, 2)); - EXPECT_EQ(kPreviousValue, index); - index = service()->GetCharacterIndexAtPoint(widget(), gfx::Point(2, 2)); - EXPECT_EQ(NSNotFound, index); - - EXPECT_EQ(2U, ipc_sink().message_count()); - for (size_t i = 0; i < ipc_sink().message_count(); ++i) { - const IPC::Message* ipc_message = ipc_sink().GetMessageAt(i); - EXPECT_EQ(ipc_message->type(), - TextInputClientMsg_CharacterIndexForPoint::ID); - } -} - -TEST_F(TextInputClientMacTest, GetRectForRange) { - ScopedTestingThread thread(this); - const NSRect kSuccessValue = NSMakeRect(42, 43, 44, 45); - - PostTask(FROM_HERE, - base::Bind(&TextInputClientMac::SetFirstRectAndSignal, - base::Unretained(service()), kSuccessValue)); - NSRect rect = service()->GetFirstRectForRange(widget(), NSMakeRange(0, 32)); - - EXPECT_EQ(1U, ipc_sink().message_count()); - EXPECT_TRUE(ipc_sink().GetUniqueMessageMatching( - TextInputClientMsg_FirstRectForCharacterRange::ID)); - EXPECT_TRUE(NSEqualRects(kSuccessValue, rect)); -} - -TEST_F(TextInputClientMacTest, TimeoutRectForRange) { - NSRect rect = service()->GetFirstRectForRange(widget(), NSMakeRange(0, 32)); - EXPECT_EQ(1U, ipc_sink().message_count()); - EXPECT_TRUE(ipc_sink().GetUniqueMessageMatching( - TextInputClientMsg_FirstRectForCharacterRange::ID)); - EXPECT_TRUE(NSEqualRects(NSZeroRect, rect)); -} - -TEST_F(TextInputClientMacTest, GetSubstring) { - ScopedTestingThread thread(this); - NSDictionary* attributes = - [NSDictionary dictionaryWithObject:[NSColor purpleColor] - forKey:NSForegroundColorAttributeName]; - scoped_nsobject kSuccessValue( - [[NSAttributedString alloc] initWithString:@"Barney is a purple dinosaur" - attributes:attributes]); - - PostTask(FROM_HERE, - base::Bind(&TextInputClientMac::SetSubstringAndSignal, - base::Unretained(service()), - base::Unretained(kSuccessValue.get()))); - NSAttributedString* string = service()->GetAttributedSubstringFromRange( - widget(), NSMakeRange(0, 32)); - - EXPECT_NSEQ(kSuccessValue, string); - EXPECT_NE(kSuccessValue.get(), string); // |string| should be a copy. - EXPECT_EQ(1U, ipc_sink().message_count()); - EXPECT_TRUE(ipc_sink().GetUniqueMessageMatching( - TextInputClientMsg_StringForRange::ID)); -} - -TEST_F(TextInputClientMacTest, TimeoutSubstring) { - NSAttributedString* string = service()->GetAttributedSubstringFromRange( - widget(), NSMakeRange(0, 32)); - EXPECT_EQ(nil, string); - EXPECT_EQ(1U, ipc_sink().message_count()); - EXPECT_TRUE(ipc_sink().GetUniqueMessageMatching( - TextInputClientMsg_StringForRange::ID)); -} - -} // namespace diff --git a/chrome/browser/renderer_host/text_input_client_message_filter.h b/chrome/browser/renderer_host/text_input_client_message_filter.h deleted file mode 100644 index 384b37a..0000000 --- a/chrome/browser/renderer_host/text_input_client_message_filter.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_RENDERER_HOST_TEXT_INPUT_CLIENT_MESSAGE_FILTER_H_ -#define CHROME_BROWSER_RENDERER_HOST_TEXT_INPUT_CLIENT_MESSAGE_FILTER_H_ -#pragma once - -#include "content/browser/browser_message_filter.h" -#include "content/common/mac/attributed_string_coder.h" - -namespace gfx { -class Rect; -} - -namespace ui { -class Range; -} - -// This is a browser-side message filter that lives on the IO thread to handle -// replies to messages sent by the TextInputClientMac. See -// chrome/browser/renderer_host/text_input_client_mac.h for more information. -class TextInputClientMessageFilter : public BrowserMessageFilter { - public: - explicit TextInputClientMessageFilter(int child_id); - virtual ~TextInputClientMessageFilter(); - - // BrowserMessageFilter override: - virtual bool OnMessageReceived(const IPC::Message& message, - bool* message_was_ok); - - private: - // IPC Message handlers: - void OnGotCharacterIndexForPoint(size_t index); - void OnGotFirstRectForRange(const gfx::Rect& rect); - void OnGotStringFromRange( - const mac::AttributedStringCoder::EncodedString& string); - - // Child process id. - int child_process_id_; - - DISALLOW_COPY_AND_ASSIGN(TextInputClientMessageFilter); -}; - -#endif // CHROME_BROWSER_RENDERER_HOST_TEXT_INPUT_CLIENT_MESSAGE_FILTER_H_ diff --git a/chrome/browser/renderer_host/text_input_client_message_filter.mm b/chrome/browser/renderer_host/text_input_client_message_filter.mm deleted file mode 100644 index fa7a10f..0000000 --- a/chrome/browser/renderer_host/text_input_client_message_filter.mm +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/renderer_host/text_input_client_message_filter.h" - -#include "base/memory/scoped_nsobject.h" -#include "base/string16.h" -#include "chrome/browser/renderer_host/text_input_client_mac.h" -#include "chrome/common/text_input_client_messages.h" -#include "content/browser/browser_thread.h" -#include "content/browser/renderer_host/render_view_host.h" -#include "content/browser/renderer_host/render_widget_host_view.h" -#include "ipc/ipc_message_macros.h" -#include "ui/base/range/range.h" -#include "ui/gfx/rect.h" - -TextInputClientMessageFilter::TextInputClientMessageFilter(int child_id) - : BrowserMessageFilter(), - child_process_id_(child_id) { -} - -TextInputClientMessageFilter::~TextInputClientMessageFilter() { -} - -bool TextInputClientMessageFilter::OnMessageReceived( - const IPC::Message& message, - bool* message_was_ok) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP_EX(TextInputClientMessageFilter, message, - *message_was_ok) - IPC_MESSAGE_HANDLER(TextInputClientReplyMsg_GotCharacterIndexForPoint, - OnGotCharacterIndexForPoint) - IPC_MESSAGE_HANDLER(TextInputClientReplyMsg_GotFirstRectForRange, - OnGotFirstRectForRange) - IPC_MESSAGE_HANDLER(TextInputClientReplyMsg_GotStringForRange, - OnGotStringFromRange) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP_EX() - return handled; -} - -void TextInputClientMessageFilter::OnGotCharacterIndexForPoint(size_t index) { - TextInputClientMac* service = TextInputClientMac::GetInstance(); - // |index| could be WTF::notFound (-1) and it's value is different from - // NSNotFound so we need to convert it. - if (index == static_cast(-1)) { - index = NSNotFound; - } - service->SetCharacterIndexAndSignal(index); -} - -void TextInputClientMessageFilter::OnGotFirstRectForRange( - const gfx::Rect& rect) { - TextInputClientMac* service = TextInputClientMac::GetInstance(); - service->SetFirstRectAndSignal(NSRectFromCGRect(rect.ToCGRect())); -} - -void TextInputClientMessageFilter::OnGotStringFromRange( - const mac::AttributedStringCoder::EncodedString& encoded_string) { - TextInputClientMac* service = TextInputClientMac::GetInstance(); - NSAttributedString* string = - mac::AttributedStringCoder::Decode(&encoded_string); - if (![string length]) - string = nil; - service->SetSubstringAndSignal(string); -} diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 6bc5646..904bbee 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1908,10 +1908,6 @@ 'browser/renderer_host/render_widget_host_view_views_win.cc', 'browser/renderer_host/safe_browsing_resource_handler.cc', 'browser/renderer_host/safe_browsing_resource_handler.h', - 'browser/renderer_host/text_input_client_mac.h', - 'browser/renderer_host/text_input_client_mac.mm', - 'browser/renderer_host/text_input_client_message_filter.h', - 'browser/renderer_host/text_input_client_message_filter.mm', 'browser/renderer_host/web_cache_manager.cc', 'browser/renderer_host/web_cache_manager.h', 'browser/renderer_preferences_util.cc', diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index 6ebc25b..ab91337 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -235,7 +235,6 @@ 'common/spellcheck_common.cc', 'common/spellcheck_common.h', 'common/spellcheck_messages.h', - 'common/text_input_client_messages.h', 'common/thumbnail_score.cc', 'common/thumbnail_score.h', 'common/url_constants.cc', diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi index 3e80022..8f63b70 100644 --- a/chrome/chrome_renderer.gypi +++ b/chrome/chrome_renderer.gypi @@ -170,8 +170,6 @@ 'renderer/spellchecker/spellcheck_worditerator.h', 'renderer/translate_helper.cc', 'renderer/translate_helper.h', - 'renderer/text_input_client_observer.cc', - 'renderer/text_input_client_observer.h', 'renderer/visitedlink_slave.cc', 'renderer/visitedlink_slave.h', ], diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 74ad1bf..1096d6e 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1427,7 +1427,6 @@ 'browser/remoting/firewall_traversal_observer_unittest.cc', 'browser/renderer_host/accelerated_plugin_view_mac_unittest.mm', 'browser/renderer_host/render_widget_host_view_mac_unittest.mm', - 'browser/renderer_host/text_input_client_mac_unittest.mm', 'browser/renderer_host/web_cache_manager_unittest.cc', 'browser/resources_util_unittest.cc', 'browser/rlz/rlz_unittest.cc', @@ -1837,6 +1836,7 @@ '../content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc', '../content/browser/renderer_host/render_view_host_unittest.cc', '../content/browser/renderer_host/render_widget_host_unittest.cc', + '../content/browser/renderer_host/text_input_client_mac_unittest.mm', '../content/browser/site_instance_unittest.cc', '../content/browser/tab_contents/navigation_controller_unittest.cc', '../content/browser/tab_contents/render_view_host_manager_unittest.cc', diff --git a/chrome/common/common_message_generator.h b/chrome/common/common_message_generator.h index 09dde68..44128db 100644 --- a/chrome/common/common_message_generator.h +++ b/chrome/common/common_message_generator.h @@ -14,5 +14,4 @@ #include "chrome/common/safe_browsing/safebrowsing_messages.h" #include "chrome/common/service_messages.h" #include "chrome/common/spellcheck_messages.h" -#include "chrome/common/text_input_client_messages.h" diff --git a/chrome/common/text_input_client_messages.h b/chrome/common/text_input_client_messages.h deleted file mode 100644 index c42a32a..0000000 --- a/chrome/common/text_input_client_messages.h +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Multiply-included message file, hence no include guard - -#include "ipc/ipc_message_macros.h" -#include "ui/base/range/range.h" -#include "ui/gfx/rect.h" - -#if defined(OS_MACOSX) -#include "content/common/mac/attributed_string_coder.h" -#endif - -#define IPC_MESSAGE_START TextInputClientMsgStart - -// Browser -> Renderer Messages //////////////////////////////////////////////// -// These messages are sent from the browser to the renderer. Each one has a -// corresponding reply message. -//////////////////////////////////////////////////////////////////////////////// - -// Tells the renderer to send back the character index for a point. -IPC_MESSAGE_ROUTED1(TextInputClientMsg_CharacterIndexForPoint, - gfx::Point) - -// Tells the renderer to send back the rectangle for a given character range. -IPC_MESSAGE_ROUTED1(TextInputClientMsg_FirstRectForCharacterRange, - ui::Range) - -// Tells the renderer to send back the text fragment in a given range. -IPC_MESSAGE_ROUTED1(TextInputClientMsg_StringForRange, - ui::Range) - -//////////////////////////////////////////////////////////////////////////////// - -// Renderer -> Browser Replies ///////////////////////////////////////////////// -// These messages are sent in reply to the above messages. -//////////////////////////////////////////////////////////////////////////////// - -// Reply message for TextInputClientMsg_CharacterIndexForPoint. -IPC_MESSAGE_ROUTED1(TextInputClientReplyMsg_GotCharacterIndexForPoint, - size_t /* character index */) - -// Reply message for TextInputClientMsg_FirstRectForCharacterRange. -IPC_MESSAGE_ROUTED1(TextInputClientReplyMsg_GotFirstRectForRange, - gfx::Rect /* frame rectangle */) - -#if defined(OS_MACOSX) -// Reply message for TextInputClientMsg_StringForRange. -IPC_MESSAGE_ROUTED1(TextInputClientReplyMsg_GotStringForRange, - mac::AttributedStringCoder::EncodedString) -#endif // defined(OS_MACOSX) - diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc index 7becf4a..7e4e08d 100644 --- a/chrome/renderer/chrome_content_renderer_client.cc +++ b/chrome/renderer/chrome_content_renderer_client.cc @@ -57,7 +57,6 @@ #include "chrome/renderer/searchbox_extension.h" #include "chrome/renderer/spellchecker/spellcheck.h" #include "chrome/renderer/spellchecker/spellcheck_provider.h" -#include "chrome/renderer/text_input_client_observer.h" #include "chrome/renderer/translate_helper.h" #include "chrome/renderer/visitedlink_slave.h" #include "content/common/view_messages.h" @@ -226,10 +225,6 @@ void ChromeContentRendererClient::RenderViewCreated(RenderView* render_view) { safe_browsing::MalwareDOMDetails::Create(render_view); #endif -#if defined(OS_MACOSX) - new TextInputClientObserver(render_view); -#endif // defined(OS_MACOSX) - PasswordAutofillManager* password_autofill_manager = new PasswordAutofillManager(render_view); AutofillAgent* autofill_agent = new AutofillAgent(render_view, diff --git a/chrome/renderer/text_input_client_observer.cc b/chrome/renderer/text_input_client_observer.cc deleted file mode 100644 index 2102267..0000000 --- a/chrome/renderer/text_input_client_observer.cc +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/renderer/text_input_client_observer.h" - -#include "base/memory/scoped_ptr.h" -#include "chrome/common/text_input_client_messages.h" -#include "content/renderer/render_view.h" -#include "ipc/ipc_message_macros.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebSubstringUtil.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" -#include "ui/gfx/rect.h" - -TextInputClientObserver::TextInputClientObserver(RenderView* render_view) - : RenderViewObserver(render_view) { -} - -TextInputClientObserver::~TextInputClientObserver() { -} - -bool TextInputClientObserver::OnMessageReceived(const IPC::Message& message) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(TextInputClientObserver, message) - IPC_MESSAGE_HANDLER(TextInputClientMsg_CharacterIndexForPoint, - OnCharacterIndexForPoint) - IPC_MESSAGE_HANDLER(TextInputClientMsg_FirstRectForCharacterRange, - OnFirstRectForCharacterRange) - IPC_MESSAGE_HANDLER(TextInputClientMsg_StringForRange, OnStringForRange) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} - -WebKit::WebView* TextInputClientObserver::webview() { - return render_view()->webview(); -} - -void TextInputClientObserver::OnCharacterIndexForPoint(gfx::Point point) { - WebKit::WebPoint web_point(point); - size_t index = webview()->focusedFrame()->characterIndexForPoint(web_point); - Send(new TextInputClientReplyMsg_GotCharacterIndexForPoint(routing_id(), - index)); -} - -void TextInputClientObserver::OnFirstRectForCharacterRange(ui::Range range) { - WebKit::WebFrame* frame = webview()->focusedFrame(); - WebKit::WebRect web_rect; - frame->firstRectForCharacterRange(range.start(), range.length(), web_rect); - gfx::Rect rect(web_rect); - Send(new TextInputClientReplyMsg_GotFirstRectForRange(routing_id(), rect)); -} - -void TextInputClientObserver::OnStringForRange(ui::Range range) { -#if defined(OS_MACOSX) - NSAttributedString* string = - WebKit::WebSubstringUtil::attributedSubstringInRange( - webview()->focusedFrame(), range.start(), range.length()); - scoped_ptr encoded( - mac::AttributedStringCoder::Encode(string)); - Send(new TextInputClientReplyMsg_GotStringForRange(routing_id(), - *encoded.get())); -#else - NOTIMPLEMENTED(); -#endif -} diff --git a/chrome/renderer/text_input_client_observer.h b/chrome/renderer/text_input_client_observer.h deleted file mode 100644 index bbd265a..0000000 --- a/chrome/renderer/text_input_client_observer.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_RENDERER_TEXT_INPUT_CLIENT_OBSERVER_H_ -#define CHROME_RENDERER_TEXT_INPUT_CLIENT_OBSERVER_H_ - -#include "base/basictypes.h" -#include "build/build_config.h" -#include "content/renderer/render_view_observer.h" -#include "ui/base/range/range.h" -#include "ui/gfx/point.h" - -namespace WebKit { -class WebView; -} - -// This is the renderer-side message filter that generates the replies for the -// messages sent by the TextInputClientMac. See -// chrome/browser/renderer_host/text_input_client_mac.h for more information. -class TextInputClientObserver : public RenderViewObserver { - public: - explicit TextInputClientObserver(RenderView* render_view); - virtual ~TextInputClientObserver(); - - // RenderViewObserver overrides: - virtual bool OnMessageReceived(const IPC::Message& message); - - private: - // Returns the WebView of the RenderView. - WebKit::WebView* webview(); - - // IPC Message handlers: - void OnCharacterIndexForPoint(gfx::Point point); - void OnFirstRectForCharacterRange(ui::Range range); - void OnStringForRange(ui::Range range); - - DISALLOW_COPY_AND_ASSIGN(TextInputClientObserver); -}; - -#endif // CHROME_RENDERER_TEXT_INPUT_CLIENT_OBSERVER_H_ -- cgit v1.1