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

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_view_win.cc

Issue 8417004: OmniboxView: Attempt to fix a crash in GetSelectedText(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes. Created 9 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/ui/views/omnibox/omnibox_view_win.h" 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <locale> 8 #include <locale>
9 #include <string> 9 #include <string>
10 10
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 // synchronously change the permanent text to the new URL. If we don't freeze 604 // synchronously change the permanent text to the new URL. If we don't freeze
605 // here, the user could potentially see a flicker of the current URL before 605 // here, the user could potentially see a flicker of the current URL before
606 // the new one reappears, which would look glitchy. 606 // the new one reappears, which would look glitchy.
607 ScopedFreeze freeze(this, GetTextObjectModel()); 607 ScopedFreeze freeze(this, GetTextObjectModel());
608 model_->OpenMatch(match, disposition, alternate_nav_url, 608 model_->OpenMatch(match, disposition, alternate_nav_url,
609 selected_line, keyword); 609 selected_line, keyword);
610 } 610 }
611 611
612 string16 OmniboxViewWin::GetText() const { 612 string16 OmniboxViewWin::GetText() const {
613 const int len = GetTextLength() + 1; 613 const int len = GetTextLength() + 1;
614 if (len <= 1)
615 return string16();
616
614 string16 str; 617 string16 str;
615 GetWindowText(WriteInto(&str, len), len); 618 GetWindowText(WriteInto(&str, len), len);
616 return str; 619 return str;
617 } 620 }
618 621
619 bool OmniboxViewWin::IsEditingOrEmpty() const { 622 bool OmniboxViewWin::IsEditingOrEmpty() const {
620 return model_->user_input_in_progress() || (GetTextLength() == 0); 623 return model_->user_input_in_progress() || (GetTextLength() == 0);
621 } 624 }
622 625
623 int OmniboxViewWin::GetIcon() const { 626 int OmniboxViewWin::GetIcon() const {
(...skipping 1478 matching lines...) Expand 10 before | Expand all | Expand 10 after
2102 long flags; 2105 long flags;
2103 selection->GetFlags(&flags); 2106 selection->GetFlags(&flags);
2104 if (flags & tomSelStartActive) 2107 if (flags & tomSelStartActive)
2105 std::swap(sel.cpMin, sel.cpMax); 2108 std::swap(sel.cpMin, sel.cpMax);
2106 } 2109 }
2107 2110
2108 string16 OmniboxViewWin::GetSelectedText() const { 2111 string16 OmniboxViewWin::GetSelectedText() const {
2109 // Figure out the length of the selection. 2112 // Figure out the length of the selection.
2110 CHARRANGE sel; 2113 CHARRANGE sel;
2111 GetSel(sel); 2114 GetSel(sel);
2115 if (sel.cpMin == sel.cpMax) // GetSelText() crashes on NULL input.
2116 return string16();
2112 2117
2113 // Grab the selected text. 2118 // Grab the selected text.
2114 string16 str; 2119 string16 str;
2115 GetSelText(WriteInto(&str, sel.cpMax - sel.cpMin + 1)); 2120 GetSelText(WriteInto(&str, sel.cpMax - sel.cpMin + 1));
2116 return str; 2121 return str;
2117 } 2122 }
2118 2123
2119 void OmniboxViewWin::SetSelection(LONG start, LONG end) { 2124 void OmniboxViewWin::SetSelection(LONG start, LONG end) {
2120 SetSel(start, end); 2125 SetSel(start, end);
2121 2126
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
2638 // PosFromChar(i) might return 0 when i is greater than 1. 2643 // PosFromChar(i) might return 0 when i is greater than 1.
2639 return font_.GetStringWidth(text) + GetHorizontalMargin(); 2644 return font_.GetStringWidth(text) + GetHorizontalMargin();
2640 } 2645 }
2641 2646
2642 bool OmniboxViewWin::IsCaretAtEnd() const { 2647 bool OmniboxViewWin::IsCaretAtEnd() const {
2643 long length = GetTextLength(); 2648 long length = GetTextLength();
2644 CHARRANGE sel; 2649 CHARRANGE sel;
2645 GetSelection(sel); 2650 GetSelection(sel);
2646 return sel.cpMin == sel.cpMax && sel.cpMin == length; 2651 return sel.cpMin == sel.cpMax && sel.cpMin == length;
2647 } 2652 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698